< Summary

Information
Class: LGDXRobotCloud.API.Areas.Identity.Controllers.UserController
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Identity/Controllers/UserController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 21
Coverable lines: 21
Total lines: 56
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
GetUser()0%620%
UpdateUser()0%620%
UpdatePassword()0%620%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Identity/Controllers/UserController.cs

#LineLine coverage
 1using System.Security.Claims;
 2using LGDXRobotCloud.API.Services.Identity;
 3using LGDXRobotCloud.Data.Models.Business.Administration;
 4using LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 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;
 10
 11namespace LGDXRobotCloud.API.Areas.Identity.Controllers;
 12
 13[ApiController]
 14[Area("Identity")]
 15[Route("[area]/[controller]")]
 16[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 017public sealed class UserController(
 018    IAuthService authService,
 019    ICurrentUserService currentUserService
 020  ) : ControllerBase
 21{
 022  private readonly IAuthService _authService = authService ?? throw new ArgumentNullException(nameof(authService));
 023  private readonly ICurrentUserService _currentUserService = currentUserService ?? throw new ArgumentNullException(nameo
 24
 25  [HttpGet("")]
 26  [ProducesResponseType(typeof(LgdxUserDto), StatusCodes.Status200OK)]
 27  [ProducesResponseType(StatusCodes.Status404NotFound)]
 28  public async Task<ActionResult<LgdxUserDto>> GetUser()
 029  {
 030    var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
 031    var user = await _currentUserService.GetUserAsync(userId!);
 032    return Ok(user.ToDto());
 033  }
 34
 35  [HttpPut("")]
 36  [ProducesResponseType(typeof(LgdxUserDto), StatusCodes.Status204NoContent)]
 37  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 38  [ProducesResponseType(StatusCodes.Status404NotFound)]
 39  public async Task<ActionResult> UpdateUser(LgdxUserUpdateDto lgdxUserUpdateDto)
 040  {
 041    var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
 042    await _currentUserService.UpdateUserAsync(userId!, lgdxUserUpdateDto.ToBusinessModel());
 043    return NoContent();
 044  }
 45
 46  [HttpPost("Password")]
 47  [ProducesResponseType(typeof(LgdxUserDto), StatusCodes.Status204NoContent)]
 48  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 49  [ProducesResponseType(StatusCodes.Status404NotFound)]
 50  public async Task<ActionResult> UpdatePassword(UpdatePasswordRequestDto updatePasswordRequestDto)
 051  {
 052    var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
 053    await _authService.UpdatePasswordAsync(userId!, updatePasswordRequestDto.ToBusinessModel());
 054    return NoContent();
 055  }
 56}