< Summary

Information
Class: LGDXRobotCloud.API.Areas.Navigation.Controllers.RobotsController
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Navigation/Controllers/RobotsControllers.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 63
Coverable lines: 63
Total lines: 142
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
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%4260%
GetRobots()0%620%
SearchRobots()100%210%
GetRobot()100%210%
CreateRobot()100%210%
SetSoftwareEmergencyStopAsync()0%620%
SetPauseTaskAssigementAsync()0%620%
UpdateRobot()0%620%
UpdateRobotChassisInfo()0%620%
TestDeleteRobot()100%210%
DeleteRobot()0%620%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Navigation/Controllers/RobotsControllers.cs

#LineLine coverage
 1using LGDXRobotCloud.API.Configurations;
 2using Microsoft.AspNetCore.Mvc;
 3using Microsoft.Extensions.Options;
 4using System.Text.Json;
 5using Microsoft.AspNetCore.Authorization;
 6using Microsoft.AspNetCore.Authentication.JwtBearer;
 7using LGDXRobotCloud.API.Authorisation;
 8using LGDXRobotCloud.Data.Models.DTOs.V1.Responses;
 9using LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 10using LGDXRobotCloud.Data.Models.DTOs.V1.Requests;
 11using LGDXRobotCloud.API.Services.Navigation;
 12using LGDXRobotCloud.Data.Models.Business.Navigation;
 13using LGDXRobotCloud.Utilities.Constants;
 14
 15namespace LGDXRobotCloud.API.Areas.Navigation.Controllers;
 16
 17[ApiController]
 18[Area("Navigation")]
 19[Route("[area]/[controller]")]
 20[Authorize(AuthenticationSchemes = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificationScheme)]
 21[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 22[ValidateLgdxUserAccess]
 023public sealed class RobotsController(
 024    IRobotService robotService,
 025    IOnlineRobotsService OnlineRobotsService,
 026    IOptionsSnapshot<LgdxRobotCloudConfiguration> options
 027  ) : ControllerBase
 28{
 029  private readonly IRobotService _robotService = robotService ?? throw new ArgumentNullException(nameof(robotService));
 030  private readonly IOnlineRobotsService _onlineRobotsService = OnlineRobotsService ?? throw new ArgumentNullException(na
 031  private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = options.Value ?? throw new ArgumentNullExc
 32
 33  [HttpGet("")]
 34  [ProducesResponseType(typeof(IEnumerable<RobotListDto>), StatusCodes.Status200OK)]
 35  public async Task<ActionResult<IEnumerable<RobotListDto>>> GetRobots(int? realmId, string? name, int pageNumber = 1, i
 036  {
 037    pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : 
 038    var (robots, paginationHelper) = await _robotService.GetRobotsAsync(realmId, name, pageNumber, pageSize);
 039    Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(paginationHelper));
 040    return Ok(robots.ToDto());
 041  }
 42
 43  [HttpGet("Search")]
 44  [ProducesResponseType(typeof(IEnumerable<RobotSearchDto>), StatusCodes.Status200OK)]
 45  public async Task<ActionResult<IEnumerable<RobotSearchDto>>> SearchRobots(int realmId, string? name, Guid? robotId)
 046  {
 047    var robots = await _robotService.SearchRobotsAsync(realmId, name, robotId);
 048    return Ok(robots.ToDto());
 049  }
 50
 51  [HttpGet("{id}", Name = "GetRobot")]
 52  [ProducesResponseType(typeof(RobotDto), StatusCodes.Status200OK)]
 53  [ProducesResponseType(StatusCodes.Status404NotFound)]
 54  public async Task<ActionResult<RobotDto>> GetRobot(Guid id)
 055  {
 056    var robot = await _robotService.GetRobotAsync(id);
 057    return Ok(robot.ToDto());
 058  }
 59
 60  [HttpPost(Name = "CreateRobot")]
 61  [ProducesResponseType(typeof(RobotCertificateIssueDto), StatusCodes.Status201Created)]
 62  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 63  public async Task<ActionResult> CreateRobot(RobotCreateDto robotCreateDto)
 064  {
 065    var robot = await _robotService.CreateRobotAsync(robotCreateDto.ToBusinessModel());
 066    return CreatedAtAction(nameof(CreateRobot), robot.ToDto());
 067  }
 68
 69  [HttpPatch("{id}/EmergencyStop")]
 70  [ProducesResponseType(StatusCodes.Status204NoContent)]
 71  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 72  public async Task<ActionResult> SetSoftwareEmergencyStopAsync(Guid id, EnableDto data)
 073  {
 074    if (await _onlineRobotsService.SetSoftwareEmergencyStopAsync(id, data.Enable))
 075    {
 076      return NoContent();
 77    }
 078    ModelState.AddModelError(nameof(id), "Robot is offline or not found.");
 079    return ValidationProblem();
 080  }
 81
 82  [HttpPatch("{id}/PauseTaskAssigement")]
 83  [ProducesResponseType(StatusCodes.Status204NoContent)]
 84  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 85  public async Task<ActionResult> SetPauseTaskAssigementAsync(Guid id, EnableDto data)
 086  {
 087    if (await _onlineRobotsService.SetPauseTaskAssigementAsync(id, data.Enable))
 088    {
 089      return NoContent();
 90    }
 091    ModelState.AddModelError(nameof(id), "Robot is offline or not found.");
 092    return ValidationProblem();
 093  }
 94
 95  [HttpPut("{id}")]
 96  [ProducesResponseType(StatusCodes.Status204NoContent)]
 97  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 98  [ProducesResponseType(StatusCodes.Status404NotFound)]
 99  public async Task<ActionResult> UpdateRobot(Guid id, RobotUpdateDto robotUpdateDto)
 0100  {
 0101    if (!await _robotService.UpdateRobotAsync(id, robotUpdateDto.ToBusinessModel()))
 0102    {
 0103      return NotFound();
 104    }
 0105    return NoContent();
 0106  }
 107
 108  [HttpPut("{id}/Chassis")]
 109  [ProducesResponseType(StatusCodes.Status204NoContent)]
 110  [ProducesResponseType(StatusCodes.Status404NotFound)]
 111  public async Task<ActionResult> UpdateRobotChassisInfo(Guid id, RobotChassisInfoUpdateDto robotChassisInfoUpdateDto)
 0112  {
 0113    if (!await _robotService.UpdateRobotChassisInfoAsync(id, robotChassisInfoUpdateDto.ToBusinessModel()))
 0114    {
 0115      return NotFound();
 116    }
 0117    return NoContent();
 0118  }
 119
 120  [HttpPost("{id}/TestDelete")]
 121  [ProducesResponseType(StatusCodes.Status200OK)]
 122  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 123  public async Task<ActionResult> TestDeleteRobot(Guid id)
 0124  {
 0125    await _robotService.TestDeleteRobotAsync(id);
 0126    return Ok();
 0127  }
 128
 129  [HttpDelete("{id}")]
 130  [ProducesResponseType(StatusCodes.Status204NoContent)]
 131  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 132  [ProducesResponseType(StatusCodes.Status404NotFound)]
 133  public async Task<ActionResult> DeleteRobot(Guid id)
 0134  {
 0135    await _robotService.TestDeleteRobotAsync(id);
 0136    if (!await _robotService.DeleteRobotAsync(id))
 0137    {
 0138      return NotFound();
 139    }
 0140    return NoContent();
 0141  }
 142}