| | 1 | | using LGDXRobotCloud.API.Authorisation; |
| | 2 | | using LGDXRobotCloud.API.Configurations; |
| | 3 | | using LGDXRobotCloud.API.Services.Navigation; |
| | 4 | | using LGDXRobotCloud.Data.Models.Business.Navigation; |
| | 5 | | using LGDXRobotCloud.Data.Models.DTOs.V1.Commands; |
| | 6 | | using LGDXRobotCloud.Data.Models.DTOs.V1.Responses; |
| | 7 | | using LGDXRobotCloud.Utilities.Constants; |
| | 8 | | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| | 9 | | using Microsoft.AspNetCore.Authorization; |
| | 10 | | using Microsoft.AspNetCore.Mvc; |
| | 11 | | using Microsoft.Extensions.Options; |
| | 12 | | using System.Text.Json; |
| | 13 | |
|
| | 14 | | namespace LGDXRobotCloud.API.Areas.Navigation.Controllers; |
| | 15 | |
|
| | 16 | | [ApiController] |
| | 17 | | [Area("Navigation")] |
| | 18 | | [Route("[area]/[controller]")] |
| | 19 | | [Authorize(AuthenticationSchemes = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificationScheme)] |
| | 20 | | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
| | 21 | | [ValidateLgdxUserAccess] |
| 0 | 22 | | public sealed class WaypointsController( |
| 0 | 23 | | IWaypointService waypointService, |
| 0 | 24 | | IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration |
| 0 | 25 | | ) : ControllerBase |
| | 26 | | { |
| 0 | 27 | | private readonly IWaypointService _waypointService = waypointService ?? throw new ArgumentNullException(nameof(waypoin |
| 0 | 28 | | private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value ?? throw |
| | 29 | |
|
| | 30 | | [HttpGet("")] |
| | 31 | | [ProducesResponseType(typeof(IEnumerable<WaypointListDto>), StatusCodes.Status200OK)] |
| | 32 | | public async Task<ActionResult<IEnumerable<WaypointListDto>>> GetWaypoints(int? realmId, string? name, int pageNumber |
| 0 | 33 | | { |
| 0 | 34 | | pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : |
| 0 | 35 | | var (waypoints, PaginationHelper) = await _waypointService.GetWaypointsAsync(realmId, name, pageNumber, pageSize); |
| 0 | 36 | | Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper)); |
| 0 | 37 | | return Ok(waypoints.ToDto()); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | [HttpGet("Search")] |
| | 41 | | [ProducesResponseType(typeof(IEnumerable<WaypointSearchDto>), StatusCodes.Status200OK)] |
| | 42 | | public async Task<ActionResult<IEnumerable<WaypointSearchDto>>> SearchWaypoints(int realmId, string? name) |
| 0 | 43 | | { |
| 0 | 44 | | var waypoints = await _waypointService.SearchWaypointsAsync(realmId, name); |
| 0 | 45 | | return Ok(waypoints.ToDto()); |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | [HttpGet("{id}", Name = "GetWaypoint")] |
| | 49 | | [ProducesResponseType(typeof(WaypointDto), StatusCodes.Status200OK)] |
| | 50 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 51 | | public async Task<ActionResult<WaypointDto>> GetWaypoint(int id) |
| 0 | 52 | | { |
| 0 | 53 | | var waypoint = await _waypointService.GetWaypointAsync(id); |
| 0 | 54 | | return Ok(waypoint.ToDto()); |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | [HttpPost("")] |
| | 58 | | [ProducesResponseType(typeof(WaypointDto), StatusCodes.Status201Created)] |
| | 59 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 60 | | public async Task<ActionResult> CreateWaypoint(WaypointCreateDto waypointCreateDto) |
| 0 | 61 | | { |
| 0 | 62 | | var waypoint = await _waypointService.CreateWaypointAsync(waypointCreateDto.ToBusinessModel()); |
| 0 | 63 | | return CreatedAtRoute(nameof(GetWaypoint), new { id = waypoint.Id }, waypoint.ToDto()); |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | [HttpPut("{id}")] |
| | 67 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | 68 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 69 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 70 | | public async Task<ActionResult> UpdateWaypoint(int id, WaypointUpdateDto waypointUpdateDto) |
| 0 | 71 | | { |
| 0 | 72 | | if (!await _waypointService.UpdateWaypointAsync(id, waypointUpdateDto.ToBusinessModel())) |
| 0 | 73 | | { |
| 0 | 74 | | return NotFound(); |
| | 75 | | } |
| 0 | 76 | | return NoContent(); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | [HttpPost("{id}/TestDelete")] |
| | 80 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | 81 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 82 | | public async Task<ActionResult> TestDeleteWaypoint(int id) |
| 0 | 83 | | { |
| 0 | 84 | | await _waypointService.TestDeleteWaypointAsync(id); |
| 0 | 85 | | return Ok(); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | [HttpDelete("{id}")] |
| | 89 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | 90 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 91 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 92 | | public async Task<ActionResult> DeleteWaypoint(int id) |
| 0 | 93 | | { |
| 0 | 94 | | await _waypointService.TestDeleteWaypointAsync(id); |
| 0 | 95 | | if (!await _waypointService.DeleteWaypointAsync(id)) |
| 0 | 96 | | { |
| 0 | 97 | | return NotFound(); |
| | 98 | | } |
| 0 | 99 | | return NoContent(); |
| 0 | 100 | | } |
| | 101 | | } |