This commit is contained in:
2021-04-30 21:15:39 +00:00
parent 79570aa882
commit 0fcdf2cf21

View File

@@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
@@ -125,7 +127,7 @@ namespace AyaNova.Api.Controllers
else
return BadRequest(new ApiErrorResponse(biz.Errors));
}
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));;
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency })); ;
}
/// <summary>
@@ -149,6 +151,29 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Get service (physical) address for this Unit
/// </summary>
/// <param name="id"></param>
/// <returns>Service address</returns>
[HttpGet("service-address/{id}")]
public async Task<IActionResult> GetUnitServiceAddress([FromRoute] long id)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Unit))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var unt = await ct.Unit.AsNoTracking().Where(x => x.Id == id).FirstOrDefaultAsync();
if (unt == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
return Ok(ApiOkResponse.Response(new
{
unit = new AddressRecord(unt.Address, unt.City, unt.Region, unt.Country, unt.Latitude, unt.Longitude)
}));
}