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