< 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: 140
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;
 13
 14namespace LGDXRobotCloud.API.Areas.Navigation.Controllers;
 15
 16[ApiController]
 17[Area("Navigation")]
 18[Route("[area]/[controller]")]
 19[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 20[ValidateLgdxUserAccess]
 021public sealed class RobotsController(
 022    IRobotService robotService,
 023    IOnlineRobotsService OnlineRobotsService,
 024    IOptionsSnapshot<LgdxRobotCloudConfiguration> options
 025  ) : ControllerBase
 26{
 027  private readonly IRobotService _robotService = robotService ?? throw new ArgumentNullException(nameof(robotService));
 028  private readonly IOnlineRobotsService _onlineRobotsService = OnlineRobotsService ?? throw new ArgumentNullException(na
 029  private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = options.Value ?? throw new ArgumentNullExc
 30
 31  [HttpGet("")]
 32  [ProducesResponseType(typeof(IEnumerable<RobotListDto>), StatusCodes.Status200OK)]
 33  public async Task<ActionResult<IEnumerable<RobotListDto>>> GetRobots(int? realmId, string? name, int pageNumber = 1, i
 034  {
 035    pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : 
 036    var (robots, paginationHelper) = await _robotService.GetRobotsAsync(realmId, name, pageNumber, pageSize);
 037    Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(paginationHelper));
 038    return Ok(robots.ToDto());
 039  }
 40
 41  [HttpGet("Search")]
 42  [ProducesResponseType(typeof(IEnumerable<RobotSearchDto>), StatusCodes.Status200OK)]
 43  public async Task<ActionResult<IEnumerable<RobotSearchDto>>> SearchRobots(int realmId, string? name, Guid? robotId)
 044  {
 045    var robots = await _robotService.SearchRobotsAsync(realmId, name, robotId);
 046    return Ok(robots.ToDto());
 047  }
 48
 49  [HttpGet("{id}", Name = "GetRobot")]
 50  [ProducesResponseType(typeof(RobotDto), StatusCodes.Status200OK)]
 51  [ProducesResponseType(StatusCodes.Status404NotFound)]
 52  public async Task<ActionResult<RobotDto>> GetRobot(Guid id)
 053  {
 054    var robot = await _robotService.GetRobotAsync(id);
 055    return Ok(robot.ToDto());
 056  }
 57
 58  [HttpPost(Name = "CreateRobot")]
 59  [ProducesResponseType(typeof(RobotCertificateIssueDto), StatusCodes.Status201Created)]
 60  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 61  public async Task<ActionResult> CreateRobot(RobotCreateDto robotCreateDto)
 062  {
 063    var robot = await _robotService.CreateRobotAsync(robotCreateDto.ToBusinessModel());
 064    return CreatedAtAction(nameof(CreateRobot), robot.ToDto());
 065  }
 66
 67  [HttpPatch("{id}/EmergencyStop")]
 68  [ProducesResponseType(StatusCodes.Status204NoContent)]
 69  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 70  public async Task<ActionResult> SetSoftwareEmergencyStopAsync(Guid id, EnableDto data)
 071  {
 072    if (await _onlineRobotsService.SetSoftwareEmergencyStopAsync(id, data.Enable))
 073    {
 074      return NoContent();
 75    }
 076    ModelState.AddModelError(nameof(id), "Robot is offline or not found.");
 077    return ValidationProblem();
 078  }
 79
 80  [HttpPatch("{id}/PauseTaskAssigement")]
 81  [ProducesResponseType(StatusCodes.Status204NoContent)]
 82  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 83  public async Task<ActionResult> SetPauseTaskAssigementAsync(Guid id, EnableDto data)
 084  {
 085    if (await _onlineRobotsService.SetPauseTaskAssigementAsync(id, data.Enable))
 086    {
 087      return NoContent();
 88    }
 089    ModelState.AddModelError(nameof(id), "Robot is offline or not found.");
 090    return ValidationProblem();
 091  }
 92
 93  [HttpPut("{id}")]
 94  [ProducesResponseType(StatusCodes.Status204NoContent)]
 95  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 96  [ProducesResponseType(StatusCodes.Status404NotFound)]
 97  public async Task<ActionResult> UpdateRobot(Guid id, RobotUpdateDto robotUpdateDto)
 098  {
 099    if (!await _robotService.UpdateRobotAsync(id, robotUpdateDto.ToBusinessModel()))
 0100    {
 0101      return NotFound();
 102    }
 0103    return NoContent();
 0104  }
 105
 106  [HttpPut("{id}/Chassis")]
 107  [ProducesResponseType(StatusCodes.Status204NoContent)]
 108  [ProducesResponseType(StatusCodes.Status404NotFound)]
 109  public async Task<ActionResult> UpdateRobotChassisInfo(Guid id, RobotChassisInfoUpdateDto robotChassisInfoUpdateDto)
 0110  {
 0111    if (!await _robotService.UpdateRobotChassisInfoAsync(id, robotChassisInfoUpdateDto.ToBusinessModel()))
 0112    {
 0113      return NotFound();
 114    }
 0115    return NoContent();
 0116  }
 117
 118  [HttpPost("{id}/TestDelete")]
 119  [ProducesResponseType(StatusCodes.Status200OK)]
 120  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 121  public async Task<ActionResult> TestDeleteRobot(Guid id)
 0122  {
 0123    await _robotService.TestDeleteRobotAsync(id);
 0124    return Ok();
 0125  }
 126
 127  [HttpDelete("{id}")]
 128  [ProducesResponseType(StatusCodes.Status204NoContent)]
 129  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 130  [ProducesResponseType(StatusCodes.Status404NotFound)]
 131  public async Task<ActionResult> DeleteRobot(Guid id)
 0132  {
 0133    await _robotService.TestDeleteRobotAsync(id);
 0134    if (!await _robotService.DeleteRobotAsync(id))
 0135    {
 0136      return NotFound();
 137    }
 0138    return NoContent();
 0139  }
 140}