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]
|
||||
[Route("exportToGoogleSheet/{id:guid}")]
|
||||
public IActionResult ExportToGoogleSheet(Guid id)
|
||||
|
||||
Reference in New Issue
Block a user