< Summary

Information
Class: Despesas.Backend.Controllers.AcessoController
Assembly: Despesas.Backend
File(s): /src/Despesas.Backend/Controllers/AcessoController.cs
Line coverage
81%
Covered lines: 26
Uncovered lines: 6
Coverable lines: 32
Total lines: 82
Line coverage: 81.2%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Post()100%11100%
SignIn()100%11100%
GoogleSignIn()0%620%
ChangePassword()75%44100%
RecoveryPassword()100%11100%
Refresh()100%11100%

File(s)

/src/Despesas.Backend/Controllers/AcessoController.cs

#LineLine coverage
 1using Despesas.Application.Abstractions;
 2using Despesas.Application.Dtos;
 3using Despesas.Application.Dtos.Core;
 4using Despesas.Backend.Controllers.Abstractions;
 5using Despesas.GlobalException.CustomExceptions.Acesso;
 6using Microsoft.AspNetCore.Authorization;
 7using Microsoft.AspNetCore.Mvc;
 8
 9namespace Despesas.Backend.Controllers;
 10
 11[Route("api/[controller]")]
 12public class AcessoController : UnitControllerBase
 13{
 14    private readonly IAcessoBusiness<AcessoDto, LoginDto> _acessoBusiness;
 15
 1816    public AcessoController(IAcessoBusiness<AcessoDto, LoginDto> acessoBusiness)
 1817    {
 1818        _acessoBusiness = acessoBusiness;
 1819    }
 20
 21    [AllowAnonymous]
 22    [HttpPost]
 23    [ProducesResponseType(200, Type = typeof(bool))]
 24    public async Task<IActionResult> Post([FromBody] AcessoDto acessoDto)
 825    {
 826        await _acessoBusiness.Create(acessoDto);
 127        return Ok(true);
 128    }
 29
 30    [AllowAnonymous]
 31    [HttpPost("SignIn")]
 32    [ProducesResponseType(StatusCodes.Status200OK)]
 33    [ProducesResponseType(400, Type = typeof(string))]
 34    [ProducesResponseType(401)]
 35    public async Task<IActionResult> SignIn([FromBody] LoginDto login)
 436    {
 437        var result = await _acessoBusiness.ValidateCredentials(login);
 138        return Ok(result);
 139    }
 40
 41    [ApiExplorerSettings(IgnoreApi = true)]
 42    [AllowAnonymous]
 43    [HttpPost("SignInWithGoogle")]
 44    public async Task<IActionResult> GoogleSignIn([FromBody] GoogleAuthenticationDto authentication)
 045    {
 046        if (!authentication.Authenticated)
 047            throw new ArgumentException("Erro ao autenticar com o Google.");
 48
 049        var authResult = await _acessoBusiness.ValidateExternalCredentials(authentication);
 050        return Ok(authResult);
 051    }
 52
 53    [ApiExplorerSettings(IgnoreApi = true)]
 54    [HttpPost("ChangePassword")]
 55    [Authorize("Bearer", Roles = "User, Admin")]
 56    public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordDto changePasswordDto)
 257    {
 258        if (changePasswordDto == null)
 159            throw new TrocaSenhaException();
 60
 161        await _acessoBusiness.ChangePassword(UserIdentity, changePasswordDto.Senha ?? "");
 162        return Ok(true);
 163    }
 64
 65    [ApiExplorerSettings(IgnoreApi = true)]
 66    [HttpPost("RecoveryPassword")]
 67    [AllowAnonymous]
 68    public async Task<IActionResult> RecoveryPassword([FromBody] string email)
 269    {
 270        await _acessoBusiness.RecoveryPassword(email);
 171        return Ok(true);
 172    }
 73
 74    [ApiExplorerSettings(IgnoreApi = true)]
 75    [HttpGet("refreshToken/{refreshToken}")]
 76    [AllowAnonymous]
 77    public async Task<IActionResult> Refresh([FromRoute] string refreshToken)
 278    {
 279        var result = await _acessoBusiness.ValidateCredentials(refreshToken);
 180        return Ok(result);
 181    }
 82}