GetConfiguration Endpoint
This commit is contained in:
@@ -168,6 +168,60 @@ public class LayersController : Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("getConfiguration/{apiKey}/{number:int}")]
|
||||||
|
public IActionResult GetConfigurationByNumber(string apiKey, int number)
|
||||||
|
{
|
||||||
|
if (apiKey != _configuration["apiKey"])
|
||||||
|
{
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
!Request.Headers.TryGetValue("Authorization", out var authHeader))
|
||||||
|
{
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
var credentialsArr = authHeader.ToString().Split(" ");
|
||||||
|
if (credentialsArr.Length != 2)
|
||||||
|
{
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1]));
|
||||||
|
var username = authValue.Split(':')[0];
|
||||||
|
var password = authValue.Split(':')[1];
|
||||||
|
if (username != _configuration["morska-user"] || password != _configuration["morska-pass"])
|
||||||
|
{
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = _db.Layers
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.AsNoTracking()
|
||||||
|
.First(x => x.Number == number && !x.IsDeleted);
|
||||||
|
|
||||||
|
if (config is null)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = config.Records?.Where(x => x.Code == "Type").FirstOrDefault();
|
||||||
|
if (type is null || type.Desc1 != "ExternalConfiguration") {
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(config);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("exportToGoogleSheet/{id:guid}")]
|
[Route("exportToGoogleSheet/{id:guid}")]
|
||||||
public IActionResult ExportToGoogleSheet(Guid id)
|
public IActionResult ExportToGoogleSheet(Guid id)
|
||||||
|
|||||||
50
WebAPI/Helpers/DbSeed/Utlis/CreateConfig.sql
Normal file
50
WebAPI/Helpers/DbSeed/Utlis/CreateConfig.sql
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
-- T3-MultiSourceSummary
|
||||||
|
DECLARE @JustForDebug TINYINT = 0;
|
||||||
|
|
||||||
|
-- SETUP VARIABLES
|
||||||
|
DECLARE @Number INT = (SELECT COUNT(id) + 1 FROM [diunabi-morska].[dbo].[Layers]);
|
||||||
|
DECLARE @CurrentTimestamp NVARCHAR(14) = FORMAT(GETDATE(), 'yyyyMMddHHmm');
|
||||||
|
DECLARE @Name NVARCHAR(50) = CONCAT(
|
||||||
|
'L', @Number, '-A-C_D3-', @CurrentTimestamp
|
||||||
|
);
|
||||||
|
DECLARE @LayerId UNIQUEIDENTIFIER = NEWID();
|
||||||
|
|
||||||
|
DECLARE @Query NVARCHAR(MAX) = '
|
||||||
|
SELECT
|
||||||
|
REPLACE(dko_Konto, ''-'', '''') +
|
||||||
|
CAST(YEAR(dko_DataDekretacji) AS VARCHAR) +
|
||||||
|
RIGHT(''0'' + CAST(MONTH(dko_DataDekretacji) AS VARCHAR), 2) AS Code,
|
||||||
|
SUM(dko_KwotaWn) AS Value
|
||||||
|
FROM [PRZYCHODNIA_MORSKA_SP_ZOO].[dbo].[dkr_Pozycja]
|
||||||
|
WHERE dko_Konto = ''402-5'' AND YEAR(dko_DataDekretacji) > 2023
|
||||||
|
GROUP BY dko_Konto, dko_DataDekretacji ,dko_DataDekretacji
|
||||||
|
ORDER BY dko_Konto, dko_DataDekretacji;
|
||||||
|
';
|
||||||
|
|
||||||
|
SELECT @Name AS Name, @Query AS Query;
|
||||||
|
|
||||||
|
IF @JustForDebug = 1
|
||||||
|
BEGIN
|
||||||
|
SELECT 'Just for debug' AS Logger;
|
||||||
|
RETURN;
|
||||||
|
END;
|
||||||
|
|
||||||
|
INSERT INTO [diunabi-morska].[dbo].[Layers]
|
||||||
|
([Id], [Number], [Name], [CreatedAt], [ModifiedAt], [IsDeleted], [CreatedById], [ModifiedById], [Type])
|
||||||
|
VALUES (@LayerId, @Number, @Name, GETDATE(), GETDATE(), 0, '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 2);
|
||||||
|
|
||||||
|
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||||
|
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||||
|
VALUES ((SELECT NEWID()), 'Type', 'ExternalConfiguration', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||||
|
|
||||||
|
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||||
|
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||||
|
VALUES ((SELECT NEWID()), 'ConfigurationType', 'D3', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||||
|
|
||||||
|
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||||
|
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||||
|
VALUES ((SELECT NEWID()), 'IsEnabled', 'True', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||||
|
|
||||||
|
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||||
|
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||||
|
VALUES ((SELECT NEWID()), 'SQL-QUERY-1', @Query, GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
###
|
###
|
||||||
http://localhost:5400/api/layers/getForPowerBI/10763478CB738D4ecb2h76g803478CB738D4e/1205
|
http://localhost:5400/api/layers/getConfiguration/10763478CB738D4ecb2h76g803478CB738D4e/5926
|
||||||
Authorization: Basic powerbi 0F9C7E2D19FSLOCgKexz2h76g802tj6a
|
Authorization: Basic morska 0F9C7E8CB738gK2h76g803478CB
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ app.Use(async (context, next) =>
|
|||||||
var token = context.Request.Headers.Authorization.ToString();
|
var token = context.Request.Headers.Authorization.ToString();
|
||||||
if (token.Length > 0
|
if (token.Length > 0
|
||||||
&& !context.Request.Path.ToString().Contains("getForPowerBI")
|
&& !context.Request.Path.ToString().Contains("getForPowerBI")
|
||||||
|
&& !context.Request.Path.ToString().Contains("getConfiguration")
|
||||||
&& !context.Request.Path.ToString().Contains("DataInbox/Add"))
|
&& !context.Request.Path.ToString().Contains("DataInbox/Add"))
|
||||||
{
|
{
|
||||||
var handler = new JwtSecurityTokenHandler();
|
var handler = new JwtSecurityTokenHandler();
|
||||||
|
|||||||
Reference in New Issue
Block a user