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