GetConfiguration Endpoint

This commit is contained in:
Michał Zieliński
2025-03-12 15:47:00 +01:00
parent b7b3bb1b70
commit 48d40be330
4 changed files with 107 additions and 2 deletions

View File

@@ -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]
[Route("exportToGoogleSheet/{id:guid}")]
public IActionResult ExportToGoogleSheet(Guid id)