< Summary

Information
Class: Despesas.Backend.Controllers.ReceitaController
Assembly: Despesas.Backend
File(s): /src/Despesas.Backend/Controllers/ReceitaController.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 87
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Get()100%11100%
GetById()100%22100%
Post()100%22100%
Put()100%22100%
Delete()100%22100%

File(s)

/src/Despesas.Backend/Controllers/ReceitaController.cs

#LineLine coverage
 1using Despesas.Application.Abstractions;
 2using Despesas.Application.Dtos;
 3using Despesas.GlobalException.CustomExceptions.Core;
 4using Domain.Entities;
 5using Microsoft.AspNetCore.Authorization;
 6using Microsoft.AspNetCore.Mvc;
 7
 8namespace Despesas.Backend.Controllers;
 9
 10public class ReceitaController : AuthController
 11{
 12    private readonly IBusinessBase<ReceitaDto, Receita> _receitaBusiness;
 1013    public ReceitaController(IBusinessBase<ReceitaDto, Receita> receitaBusiness)
 1014    {
 1015        _receitaBusiness = receitaBusiness;
 1016    }
 17
 18    [HttpGet]
 19    [Authorize("Bearer", Roles = "User, Admin")]
 20    [ProducesResponseType(200, Type = typeof(IList<ReceitaDto>))]
 21    [ProducesResponseType(400, Type = typeof(string))]
 22    [ProducesResponseType(401)]
 23    [ProducesResponseType(403)]
 24    public async Task<IActionResult> Get()
 125    {
 126        return Ok(await _receitaBusiness.FindAll(UserIdentity));
 127    }
 28
 29    [HttpGet("GetById/{id}")]
 30    [Authorize("Bearer", Roles = "User, Admin")]
 31    [ProducesResponseType(200, Type = typeof(ReceitaDto))]
 32    [ProducesResponseType(400, Type = typeof(string))]
 33    [ProducesResponseType(401)]
 34    [ProducesResponseType(403)]
 35    public async Task<IActionResult> GetById([FromRoute] Guid id)
 236    {
 237        var _receita = await _receitaBusiness.FindById(id, UserIdentity)
 238            ?? throw new CustomException("Nenhuma receita foi encontrada.");
 139        return Ok(_receita);
 140    }
 41
 42    [HttpPost]
 43    [Authorize("Bearer", Roles = "User, Admin")]
 44    [ProducesResponseType(200, Type = typeof(ReceitaDto))]
 45    [ProducesResponseType(400, Type = typeof(string))]
 46    [ProducesResponseType(401)]
 47    [ProducesResponseType(403)]
 48    public async Task<IActionResult> Post([FromBody] ReceitaDto receita)
 249    {
 250        receita.UsuarioId = UserIdentity;
 251        receita = await _receitaBusiness.Create(receita)
 252            ?? throw new CustomException("Não foi possível realizar o cadastro da receita!");
 153        return Ok(receita);
 154    }
 55
 56    [HttpPut]
 57    [Authorize("Bearer", Roles = "User, Admin")]
 58    [ProducesResponseType(200, Type = typeof(ReceitaDto))]
 59    [ProducesResponseType(400, Type = typeof(string))]
 60    [ProducesResponseType(401)]
 61    [ProducesResponseType(403)]
 62    public async Task<IActionResult> Put([FromBody] ReceitaDto receita)
 263    {
 264        receita.UsuarioId = UserIdentity;
 265        receita = await _receitaBusiness.Update(receita)
 266            ?? throw new CustomException("Não foi possível atualizar o cadastro da receita.");
 167        return Ok(receita);
 168    }
 69
 70    [HttpDelete("{idReceita}")]
 71    [Authorize("Bearer", Roles = "User, Admin")]
 72    [ProducesResponseType(200, Type = typeof(bool))]
 73    [ProducesResponseType(400, Type = typeof(string))]
 74    [ProducesResponseType(401)]
 75    [ProducesResponseType(403)]
 76    public async Task<IActionResult> Delete(Guid idReceita)
 377    {
 78
 379        var despesa = new ReceitaDto
 380        {
 381            Id = idReceita,
 382            UsuarioId = UserIdentity
 383        };
 84
 385        return await _receitaBusiness.Delete(despesa) ? Ok(true) : BadRequest("Erro ao excluir Receita!");
 386    }
 87}