|  |  | 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 LGDXRobotCloud.Utilities.Constants; | 
|  |  | 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 = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificateScheme)] | 
|  |  | 19 |  | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] | 
|  |  | 20 |  | [ValidateLgdxUserAccess] | 
|  | 0 | 21 |  | public class TriggerRetriesController ( | 
|  | 0 | 22 |  |   IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration, | 
|  | 0 | 23 |  |   ITriggerRetryService triggerRetryService | 
|  | 0 | 24 |  | ) : ControllerBase | 
|  |  | 25 |  | { | 
|  | 0 | 26 |  |   private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value ?? throw | 
|  | 0 | 27 |  |   private readonly ITriggerRetryService _triggerRetryService = triggerRetryService ?? throw new ArgumentNullException(na | 
|  |  | 28 |  |  | 
|  |  | 29 |  |   [HttpGet("")] | 
|  |  | 30 |  |   [ProducesResponseType(typeof(IEnumerable<TriggerRetryListDto>), StatusCodes.Status200OK)] | 
|  |  | 31 |  |   public async Task<ActionResult<IEnumerable<TriggerRetryListDto>>> GetTriggerRetries(int pageNumber = 1, int pageSize = | 
|  | 0 | 32 |  |   { | 
|  | 0 | 33 |  |     pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize :  | 
|  | 0 | 34 |  |     var (triggerRetries, PaginationHelper) = await _triggerRetryService.GetTriggerRetriesAsync(pageNumber, pageSize); | 
|  | 0 | 35 |  |     Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper)); | 
|  | 0 | 36 |  |     return Ok(triggerRetries.ToDto()); | 
|  | 0 | 37 |  |   } | 
|  |  | 38 |  |  | 
|  |  | 39 |  |   [HttpGet("{id}", Name = "GetTriggerRetry")] | 
|  |  | 40 |  |   [ProducesResponseType(typeof(TriggerRetryDto), StatusCodes.Status200OK)] | 
|  |  | 41 |  |   [ProducesResponseType(StatusCodes.Status404NotFound)] | 
|  |  | 42 |  |   public async Task<ActionResult<TriggerRetryDto>> GetTriggerRetry(int id) | 
|  | 0 | 43 |  |   { | 
|  | 0 | 44 |  |     var triggerRetry = await _triggerRetryService.GetTriggerRetryAsync(id); | 
|  | 0 | 45 |  |     return Ok(triggerRetry.ToDto()); | 
|  | 0 | 46 |  |   } | 
|  |  | 47 |  |  | 
|  |  | 48 |  |   [HttpPost("{id}/Retry")] | 
|  |  | 49 |  |   [ProducesResponseType(StatusCodes.Status204NoContent)] | 
|  |  | 50 |  |   [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] | 
|  |  | 51 |  |   [ProducesResponseType(StatusCodes.Status404NotFound)] | 
|  |  | 52 |  |   public async Task<ActionResult<TriggerRetryDto>> RetryTriggerRetry(int id) | 
|  | 0 | 53 |  |   { | 
|  | 0 | 54 |  |     await _triggerRetryService.RetryTriggerRetryAsync(id); | 
|  | 0 | 55 |  |     return NoContent(); | 
|  | 0 | 56 |  |   } | 
|  |  | 57 |  |  | 
|  |  | 58 |  |   [HttpPost("Triggers/{triggerId}/Retry")] | 
|  |  | 59 |  |   [ProducesResponseType(StatusCodes.Status204NoContent)] | 
|  |  | 60 |  |   [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] | 
|  |  | 61 |  |   [ProducesResponseType(StatusCodes.Status404NotFound)] | 
|  |  | 62 |  |   public async Task<ActionResult<TriggerRetryDto>> RetryAllFailedTrigger(int triggerId) | 
|  | 0 | 63 |  |   { | 
|  | 0 | 64 |  |     await _triggerRetryService.RetryAllFailedTriggerAsync(triggerId); | 
|  | 0 | 65 |  |     return NoContent(); | 
|  | 0 | 66 |  |   } | 
|  |  | 67 |  |  | 
|  |  | 68 |  |   [HttpDelete("{id}")] | 
|  |  | 69 |  |   [ProducesResponseType(StatusCodes.Status204NoContent)] | 
|  |  | 70 |  |   [ProducesResponseType(StatusCodes.Status404NotFound)] | 
|  |  | 71 |  |   public async Task<ActionResult> DeleteTriggerRetry(int id) | 
|  | 0 | 72 |  |   { | 
|  | 0 | 73 |  |     if (await _triggerRetryService.DeleteTriggerRetryAsync(id)) | 
|  | 0 | 74 |  |     { | 
|  | 0 | 75 |  |       return NoContent(); | 
|  |  | 76 |  |     } | 
|  |  | 77 |  |     else | 
|  | 0 | 78 |  |     { | 
|  | 0 | 79 |  |       return NotFound(); | 
|  |  | 80 |  |     } | 
|  | 0 | 81 |  |   } | 
|  |  | 82 |  | } |