< Summary

Information
Class: LGDXRobotCloud.API.Areas.Administration.Controllers.RobotCertificatesController
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Administration/Controllers/RobotCertificatesController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 69
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%2040%
GetCertificates()0%620%
GetRootCertificate()0%620%
GetCertificate()100%210%
RenewCertificate()100%210%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Administration/Controllers/RobotCertificatesController.cs

#LineLine coverage
 1using LGDXRobotCloud.API.Authorisation;
 2using LGDXRobotCloud.API.Configurations;
 3using LGDXRobotCloud.API.Services.Administration;
 4using LGDXRobotCloud.Data.Models.Business.Administration;
 5using LGDXRobotCloud.Data.Models.DTOs.V1.Requests;
 6using LGDXRobotCloud.Data.Models.DTOs.V1.Responses;
 7using Microsoft.AspNetCore.Authentication.JwtBearer;
 8using Microsoft.AspNetCore.Authorization;
 9using Microsoft.AspNetCore.Mvc;
 10using Microsoft.Extensions.Options;
 11using System.Text.Json;
 12
 13namespace LGDXRobotCloud.API.Areas.Administration.Controllers;
 14
 15[ApiController]
 16[Area("Administration")]
 17[Route("[area]/[controller]")]
 18[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 19[ValidateLgdxUserAccess]
 020public sealed class RobotCertificatesController(
 021    IRobotCertificateService robotCertificateService,
 022    IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration
 023  ) : ControllerBase
 24{
 025  private readonly IRobotCertificateService _robotCertificateService = robotCertificateService ?? throw new ArgumentNull
 026  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
 031  {
 032    pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : 
 033    var (certificates, PaginationHelper) = await _robotCertificateService.GetRobotCertificatesAsync(pageNumber, pageSize
 034    Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper));
 035    return Ok(certificates.ToDto());
 036  }
 37
 38  [HttpGet("Root")]
 39  [ProducesResponseType(typeof(RootCertificateDto), StatusCodes.Status200OK)]
 40  [ProducesResponseType(StatusCodes.Status404NotFound)]
 41  public ActionResult<RootCertificateDto> GetRootCertificate()
 042  {
 043    var rootCertificate = _robotCertificateService.GetRootCertificate();
 044    if (rootCertificate == null)
 045      return NotFound();
 046    return Ok(rootCertificate.ToDto());
 047  }
 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)
 053  {
 054    var certificate = await _robotCertificateService.GetRobotCertificateAsync(id);
 055    return Ok(certificate.ToDto());
 056  }
 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
 062  {
 063    var robotCertificate = await _robotCertificateService.RenewRobotCertificateAsync(new() {
 064      CertificateId = id,
 065      RevokeOldCertificate = robotCertificateRenewRequestDto.RevokeOldCertificate
 066    });
 067    return Ok(robotCertificate.ToDto());
 068  }
 69}