| | 1 | | using LGDXRobotCloud.API.Authorisation; |
| | 2 | | using LGDXRobotCloud.API.Configurations; |
| | 3 | | using LGDXRobotCloud.API.Services.Automation; |
| | 4 | | using LGDXRobotCloud.Data.Models.Business.Automation; |
| | 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.Automation.Controllers; |
| | 14 | |
|
| | 15 | | [ApiController] |
| | 16 | | [Area("Automation")] |
| | 17 | | [Route("[area]/[controller]")] |
| | 18 | | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
| | 19 | | [ValidateLgdxUserAccess] |
| 0 | 20 | | public sealed class ProgressesController( |
| 0 | 21 | | IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration, |
| 0 | 22 | | IProgressService progressService |
| 0 | 23 | | ) : ControllerBase |
| | 24 | | { |
| 0 | 25 | | private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value ?? throw |
| 0 | 26 | | private readonly IProgressService _progressService = progressService ?? throw new ArgumentNullException(nameof(progres |
| | 27 | |
|
| | 28 | | [HttpGet("")] |
| | 29 | | [ProducesResponseType(typeof(IEnumerable<ProgressDto>), StatusCodes.Status200OK)] |
| | 30 | | public async Task<ActionResult<IEnumerable<ProgressDto>>> GetProgresses(string? name, int pageNumber = 1, int pageSize |
| 0 | 31 | | { |
| 0 | 32 | | pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : |
| 0 | 33 | | var (progresses, PaginationHelper) = await _progressService.GetProgressesAsync(name, pageNumber, pageSize, system); |
| 0 | 34 | | Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper)); |
| 0 | 35 | | return Ok(progresses.ToDto()); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | [HttpGet("Search")] |
| | 39 | | [ProducesResponseType(typeof(IEnumerable<ProgressSearchDto>), StatusCodes.Status200OK)] |
| | 40 | | public async Task<ActionResult<IEnumerable<ProgressSearchDto>>> SearchProgresses(string? name, bool reserved = false) |
| 0 | 41 | | { |
| 0 | 42 | | var progresses = await _progressService.SearchProgressesAsync(name, reserved); |
| 0 | 43 | | return Ok(progresses.ToDto()); |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | [HttpGet("{id}", Name = "GetProgress")] |
| | 47 | | [ProducesResponseType(typeof(ProgressDto), StatusCodes.Status200OK)] |
| | 48 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 49 | | public async Task<ActionResult<ProgressDto>> GetProgress(int id) |
| 0 | 50 | | { |
| 0 | 51 | | var progress = await _progressService.GetProgressAsync(id); |
| 0 | 52 | | return Ok(progress.ToDto()); |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | [HttpPost("")] |
| | 56 | | [ProducesResponseType(typeof(ProgressDto), StatusCodes.Status201Created)] |
| | 57 | | public async Task<ActionResult> CreateProgress(ProgressCreateDto progressCreateDto) |
| 0 | 58 | | { |
| 0 | 59 | | var progress = await _progressService.CreateProgressAsync(progressCreateDto.ToBusinessModel()); |
| 0 | 60 | | return CreatedAtRoute(nameof(GetProgress), new { id = progress.Id }, progress.ToDto()); |
| 0 | 61 | | } |
| | 62 | |
|
| | 63 | | [HttpPut("{id}")] |
| | 64 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | 65 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 66 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 67 | | public async Task<ActionResult> UpdateProgress(int id, ProgressUpdateDto progressUpdateDto) |
| 0 | 68 | | { |
| 0 | 69 | | await _progressService.UpdateProgressAsync(id, progressUpdateDto.ToBusinessModel()); |
| 0 | 70 | | return NoContent(); |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | [HttpPost("{id}/TestDelete")] |
| | 74 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | 75 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 76 | | public async Task<ActionResult> TestDeleteProgress(int id) |
| 0 | 77 | | { |
| 0 | 78 | | await _progressService.TestDeleteProgressAsync(id); |
| 0 | 79 | | return Ok(); |
| 0 | 80 | | } |
| | 81 | |
|
| | 82 | | [HttpDelete("{id}")] |
| | 83 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | 84 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 85 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 86 | | public async Task<ActionResult> DeleteProgress(int id) |
| 0 | 87 | | { |
| 0 | 88 | | await _progressService.TestDeleteProgressAsync(id); |
| 0 | 89 | | await _progressService.DeleteProgressAsync(id); |
| 0 | 90 | | return NoContent(); |
| 0 | 91 | | } |
| | 92 | | } |