< Summary

Information
Class: LGDXRobotCloud.API.Areas.Navigation.Controllers.RealmsController
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Navigation/Controllers/RealmsController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 43
Coverable lines: 43
Total lines: 104
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%620%
GetRealms()0%620%
SearchRealms()100%210%
GetRealm()100%210%
GetDefaultRealm()100%210%
CreateRealm()100%210%
UpdateRealm()0%620%
TestDeleteRealm()100%210%
DeleteRealm()0%620%

File(s)

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

#LineLine coverage
 1using System.Text.Json;
 2using LGDXRobotCloud.API.Authorisation;
 3using LGDXRobotCloud.API.Services.Navigation;
 4using LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 5using LGDXRobotCloud.Data.Models.DTOs.V1.Responses;
 6using LGDXRobotCloud.Data.Models.Business.Navigation;
 7using Microsoft.AspNetCore.Authentication.JwtBearer;
 8using Microsoft.AspNetCore.Authorization;
 9using Microsoft.AspNetCore.Mvc;
 10using LGDXRobotCloud.Utilities.Constants;
 11
 12namespace LGDXRobotCloud.API.Areas.Navigation.Controllers;
 13
 14[ApiController]
 15[Area("Navigation")]
 16[Route("[area]/[controller]")]
 17[Authorize(AuthenticationSchemes = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificationScheme)]
 18[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 19[ValidateLgdxUserAccess]
 020public class RealmsController(
 021  IRealmService realmService
 022) : ControllerBase
 23{
 024  private readonly IRealmService _realmService = realmService ?? throw new ArgumentNullException(nameof(realmService));
 25
 26  [HttpGet("")]
 27  [ProducesResponseType(typeof(IEnumerable<RealmListDto>), StatusCodes.Status200OK)]
 28  public async Task<ActionResult<IEnumerable<RealmListDto>>> GetRealms(string? name, int pageNumber = 1, int pageSize = 
 029  {
 030    pageSize = (pageSize > 100) ? 100 : pageSize;
 031    var (realms, PaginationHelper) = await _realmService.GetRealmsAsync(name, pageNumber, pageSize);
 032    Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper));
 033    return Ok(realms.ToDto());
 034  }
 35
 36  [HttpGet("Search")]
 37  [ProducesResponseType(typeof(IEnumerable<RealmSearchDto>), StatusCodes.Status200OK)]
 38  public async Task<ActionResult<IEnumerable<RealmSearchDto>>> SearchRealms(string? name)
 039  {
 040    var realms = await _realmService.SearchRealmsAsync(name);
 041    return Ok(realms.ToDto());
 042  }
 43
 44  [HttpGet("{id}", Name = "GetRealm")]
 45  [ProducesResponseType(typeof(RealmDto), StatusCodes.Status200OK)]
 46  [ProducesResponseType(StatusCodes.Status404NotFound)]
 47  public async Task<ActionResult<RealmDto>> GetRealm(int id)
 048  {
 049    var realm = await _realmService.GetRealmAsync(id);
 050    return Ok(realm.ToDto());
 051  }
 52
 53  [HttpGet("Default")]
 54  [ProducesResponseType(typeof(RealmDto), StatusCodes.Status200OK)]
 55  [ProducesResponseType(StatusCodes.Status404NotFound)]
 56  public async Task<ActionResult<RealmDto>> GetDefaultRealm()
 057  {
 058    var realm = await _realmService.GetDefaultRealmAsync();
 059    return Ok(realm.ToDto());
 060  }
 61
 62  [HttpPost("")]
 63  [ProducesResponseType(typeof(RealmDto), StatusCodes.Status201Created)]
 64  public async Task<ActionResult> CreateRealm(RealmCreateDto realmCreateDto)
 065  {
 066    var realm = await _realmService.CreateRealmAsync(realmCreateDto.ToBusinessModel());
 067    return CreatedAtAction(nameof(GetRealm), new { id = realm.Id }, realm.ToDto());
 068  }
 69
 70  [HttpPut("{id}")]
 71  [ProducesResponseType(StatusCodes.Status204NoContent)]
 72  [ProducesResponseType(StatusCodes.Status404NotFound)]
 73  public async Task<ActionResult> UpdateRealm(int id, RealmUpdateDto realmUpdateDto)
 074  {
 075    if (!await _realmService.UpdateRealmAsync(id, realmUpdateDto.ToBusinessModel()))
 076    {
 077      return NotFound();
 78    }
 079    return NoContent();
 080  }
 81
 82  [HttpPost("{id}/TestDelete")]
 83  [ProducesResponseType(StatusCodes.Status200OK)]
 84  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 85  public async Task<ActionResult> TestDeleteRealm(int id)
 086  {
 087    await _realmService.TestDeleteRealmAsync(id);
 088    return Ok();
 089  }
 90
 91  [HttpDelete("{id}")]
 92  [ProducesResponseType(StatusCodes.Status204NoContent)]
 93  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 94  [ProducesResponseType(StatusCodes.Status404NotFound)]
 95  public async Task<ActionResult> DeleteRealm(int id)
 096  {
 097    await _realmService.TestDeleteRealmAsync(id);
 098    if (!await _realmService.DeleteRealmAsync(id))
 099    {
 0100      return NotFound();
 101    }
 0102    return NoContent();
 0103  }
 104}