| | 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.Responses; |
| | 6 | | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| | 7 | | using Microsoft.AspNetCore.Authorization; |
| | 8 | | using Microsoft.AspNetCore.Mvc; |
| | 9 | | using Microsoft.Extensions.Options; |
| | 10 | | using System.Text.Json; |
| | 11 | |
|
| | 12 | | namespace LGDXRobotCloud.API.Areas.Automation.Controllers; |
| | 13 | |
|
| | 14 | | [ApiController] |
| | 15 | | [Area("Automation")] |
| | 16 | | [Route("[area]/[controller]")] |
| | 17 | | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
| | 18 | | [ValidateLgdxUserAccess] |
| 0 | 19 | | public class TriggerRetriesController ( |
| 0 | 20 | | IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration, |
| 0 | 21 | | ITriggerRetryService triggerRetryService |
| 0 | 22 | | ) : ControllerBase |
| | 23 | | { |
| 0 | 24 | | private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value ?? throw |
| 0 | 25 | | private readonly ITriggerRetryService _triggerRetryService = triggerRetryService ?? throw new ArgumentNullException(na |
| | 26 | |
|
| | 27 | | [HttpGet("")] |
| | 28 | | [ProducesResponseType(typeof(IEnumerable<TriggerRetryListDto>), StatusCodes.Status200OK)] |
| | 29 | | public async Task<ActionResult<IEnumerable<TriggerRetryListDto>>> GetTriggerRetries(int pageNumber = 1, int pageSize = |
| 0 | 30 | | { |
| 0 | 31 | | pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : |
| 0 | 32 | | var (triggerRetries, PaginationHelper) = await _triggerRetryService.GetTriggerRetriesAsync(pageNumber, pageSize); |
| 0 | 33 | | Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper)); |
| 0 | 34 | | return Ok(triggerRetries.ToDto()); |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | [HttpGet("{id}", Name = "GetTriggerRetry")] |
| | 38 | | [ProducesResponseType(typeof(TriggerRetryDto), StatusCodes.Status200OK)] |
| | 39 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 40 | | public async Task<ActionResult<TriggerRetryDto>> GetTriggerRetry(int id) |
| 0 | 41 | | { |
| 0 | 42 | | var triggerRetry = await _triggerRetryService.GetTriggerRetryAsync(id); |
| 0 | 43 | | return Ok(triggerRetry.ToDto()); |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | [HttpPost("{id}/Retry")] |
| | 47 | | [ProducesResponseType(typeof(TriggerRetryDto), StatusCodes.Status204NoContent)] |
| | 48 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 49 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 50 | | public async Task<ActionResult<TriggerRetryDto>> RetryTriggerRetry(int id) |
| 0 | 51 | | { |
| 0 | 52 | | await _triggerRetryService.RetryTriggerRetryAsync(id); |
| 0 | 53 | | return NoContent(); |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | [HttpDelete("{id}")] |
| | 57 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | 58 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 59 | | public async Task<ActionResult> DeleteTriggerRetry(int id) |
| 0 | 60 | | { |
| 0 | 61 | | if (await _triggerRetryService.DeleteTriggerRetryAsync(id)) |
| 0 | 62 | | { |
| 0 | 63 | | return NoContent(); |
| | 64 | | } |
| | 65 | | else |
| 0 | 66 | | { |
| 0 | 67 | | return NotFound(); |
| | 68 | | } |
| 0 | 69 | | } |
| | 70 | | } |