From 0fcdf2cf21ddf406d9f48d5728015fc58cd8c4b5 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 30 Apr 2021 21:15:39 +0000 Subject: [PATCH] --- server/AyaNova/Controllers/UnitController.cs | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/server/AyaNova/Controllers/UnitController.cs b/server/AyaNova/Controllers/UnitController.cs index e297ce11..e8256367 100644 --- a/server/AyaNova/Controllers/UnitController.cs +++ b/server/AyaNova/Controllers/UnitController.cs @@ -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 })); ; } /// @@ -149,6 +151,29 @@ namespace AyaNova.Api.Controllers } + /// + /// Get service (physical) address for this Unit + /// + /// + /// Service address + [HttpGet("service-address/{id}")] + public async Task 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) + })); + }