| | 1 | | using LGDXRobotCloud.API.Authorisation; |
| | 2 | | using LGDXRobotCloud.API.Configurations; |
| | 3 | | using LGDXRobotCloud.API.Services.Administration; |
| | 4 | | using LGDXRobotCloud.Data.Models.Business.Administration; |
| | 5 | | using LGDXRobotCloud.Data.Models.DTOs.V1.Requests; |
| | 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.Administration.Controllers; |
| | 14 | |
|
| | 15 | | [ApiController] |
| | 16 | | [Area("Administration")] |
| | 17 | | [Route("[area]/[controller]")] |
| | 18 | | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
| | 19 | | [ValidateLgdxUserAccess] |
| 0 | 20 | | public sealed class RobotCertificatesController( |
| 0 | 21 | | IRobotCertificateService robotCertificateService, |
| 0 | 22 | | IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration |
| 0 | 23 | | ) : ControllerBase |
| | 24 | | { |
| 0 | 25 | | private readonly IRobotCertificateService _robotCertificateService = robotCertificateService ?? throw new ArgumentNull |
| 0 | 26 | | private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value ?? throw |
| | 27 | |
|
| | 28 | | [HttpGet("")] |
| | 29 | | [ProducesResponseType(typeof(IEnumerable<RobotCertificateListDto>), StatusCodes.Status200OK)] |
| | 30 | | public async Task<ActionResult<IEnumerable<RobotCertificateListDto>>> GetCertificates(int pageNumber = 1, int pageSize |
| 0 | 31 | | { |
| 0 | 32 | | pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : |
| 0 | 33 | | var (certificates, PaginationHelper) = await _robotCertificateService.GetRobotCertificatesAsync(pageNumber, pageSize |
| 0 | 34 | | Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper)); |
| 0 | 35 | | return Ok(certificates.ToDto()); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | [HttpGet("Root")] |
| | 39 | | [ProducesResponseType(typeof(RootCertificateDto), StatusCodes.Status200OK)] |
| | 40 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 41 | | public ActionResult<RootCertificateDto> GetRootCertificate() |
| 0 | 42 | | { |
| 0 | 43 | | var rootCertificate = _robotCertificateService.GetRootCertificate(); |
| 0 | 44 | | if (rootCertificate == null) |
| 0 | 45 | | return NotFound(); |
| 0 | 46 | | return Ok(rootCertificate.ToDto()); |
| 0 | 47 | | } |
| | 48 | |
|
| | 49 | | [HttpGet("{id}", Name = "GetCertificate")] |
| | 50 | | [ProducesResponseType(typeof(RobotCertificateDto), StatusCodes.Status200OK)] |
| | 51 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 52 | | public async Task<ActionResult<RobotCertificateDto>> GetCertificate(Guid id) |
| 0 | 53 | | { |
| 0 | 54 | | var certificate = await _robotCertificateService.GetRobotCertificateAsync(id); |
| 0 | 55 | | return Ok(certificate.ToDto()); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | [HttpPost("{id}/Renew")] |
| | 59 | | [ProducesResponseType(typeof(RobotCertificateIssueDto), StatusCodes.Status200OK)] |
| | 60 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 61 | | public async Task<ActionResult<RobotCertificateIssueDto>> RenewCertificate(Guid id, RobotCertificateRenewRequestDto ro |
| 0 | 62 | | { |
| 0 | 63 | | var robotCertificate = await _robotCertificateService.RenewRobotCertificateAsync(new() { |
| 0 | 64 | | CertificateId = id, |
| 0 | 65 | | RevokeOldCertificate = robotCertificateRenewRequestDto.RevokeOldCertificate |
| 0 | 66 | | }); |
| 0 | 67 | | return Ok(robotCertificate.ToDto()); |
| 0 | 68 | | } |
| | 69 | | } |