< 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: 71
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 LGDXRobotCloud.Utilities.Constants;
 8using Microsoft.AspNetCore.Authentication.JwtBearer;
 9using Microsoft.AspNetCore.Authorization;
 10using Microsoft.AspNetCore.Mvc;
 11using Microsoft.Extensions.Options;
 12using System.Text.Json;
 13
 14namespace LGDXRobotCloud.API.Areas.Administration.Controllers;
 15
 16[ApiController]
 17[Area("Administration")]
 18[Route("[area]/[controller]")]
 19[Authorize(AuthenticationSchemes = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificationScheme)]
 20[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 21[ValidateLgdxUserAccess]
 022public sealed class RobotCertificatesController(
 023    IRobotCertificateService robotCertificateService,
 024    IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration
 025  ) : ControllerBase
 26{
 027  private readonly IRobotCertificateService _robotCertificateService = robotCertificateService ?? throw new ArgumentNull
 028  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
 033  {
 034    pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : 
 035    var (certificates, PaginationHelper) = await _robotCertificateService.GetRobotCertificatesAsync(pageNumber, pageSize
 036    Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper));
 037    return Ok(certificates.ToDto());
 038  }
 39
 40  [HttpGet("Root")]
 41  [ProducesResponseType(typeof(RootCertificateDto), StatusCodes.Status200OK)]
 42  [ProducesResponseType(StatusCodes.Status404NotFound)]
 43  public ActionResult<RootCertificateDto> GetRootCertificate()
 044  {
 045    var rootCertificate = _robotCertificateService.GetRootCertificate();
 046    if (rootCertificate == null)
 047      return NotFound();
 048    return Ok(rootCertificate.ToDto());
 049  }
 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)
 055  {
 056    var certificate = await _robotCertificateService.GetRobotCertificateAsync(id);
 057    return Ok(certificate.ToDto());
 058  }
 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
 064  {
 065    var robotCertificate = await _robotCertificateService.RenewRobotCertificateAsync(new() {
 066      CertificateId = id,
 067      RevokeOldCertificate = robotCertificateRenewRequestDto.RevokeOldCertificate
 068    });
 069    return Ok(robotCertificate.ToDto());
 070  }
 71}