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