| | 1 | | using Despesas.Application.Abstractions; |
| | 2 | | using Despesas.Application.Dtos; |
| | 3 | | using Microsoft.AspNetCore.Authorization; |
| | 4 | | using Microsoft.AspNetCore.Mvc; |
| | 5 | |
|
| | 6 | | namespace Despesas.Backend.Controllers; |
| | 7 | |
|
| | 8 | | public class SaldoController : AuthController |
| | 9 | | { |
| | 10 | | private ISaldoBusiness _saldoBusiness; |
| 6 | 11 | | public SaldoController(ISaldoBusiness saldoBusiness) |
| 6 | 12 | | { |
| 6 | 13 | | _saldoBusiness = saldoBusiness; |
| 6 | 14 | | } |
| | 15 | |
|
| | 16 | | [HttpGet] |
| | 17 | | [Authorize("Bearer", Roles = "User, Admin")] |
| | 18 | | [ProducesResponseType(200, Type = typeof(SaldoDto))] |
| | 19 | | [ProducesResponseType(400, Type = typeof(string))] |
| | 20 | | [ProducesResponseType(401)] |
| | 21 | | [ProducesResponseType(403)] |
| | 22 | | public async Task<IActionResult> Get() |
| 2 | 23 | | { |
| | 24 | | try |
| 2 | 25 | | { |
| 2 | 26 | | var saldo = await _saldoBusiness.GetSaldo(UserIdentity); |
| 1 | 27 | | return Ok(saldo); |
| | 28 | | } |
| 1 | 29 | | catch |
| 1 | 30 | | { |
| 1 | 31 | | return BadRequest("Erro ao gerar saldo!"); |
| | 32 | | } |
| 2 | 33 | | } |
| | 34 | |
|
| | 35 | | [HttpGet("ByAno/{ano}")] |
| | 36 | | [Authorize("Bearer", Roles = "User, Admin")] |
| | 37 | | [ProducesResponseType(200, Type = typeof(SaldoDto))] |
| | 38 | | [ProducesResponseType(400, Type = typeof(string))] |
| | 39 | | [ProducesResponseType(401)] |
| | 40 | | [ProducesResponseType(403)] |
| | 41 | | public async Task<IActionResult> GetSaldoByAno([FromRoute] DateTime ano) |
| 2 | 42 | | { |
| | 43 | | try |
| 2 | 44 | | { |
| 2 | 45 | | var saldo = await _saldoBusiness.GetSaldoAnual(ano, UserIdentity); |
| 1 | 46 | | return Ok(saldo); |
| | 47 | | } |
| 1 | 48 | | catch |
| 1 | 49 | | { |
| 1 | 50 | | return BadRequest("Erro ao gerar saldo!"); |
| | 51 | | } |
| 2 | 52 | | } |
| | 53 | |
|
| | 54 | | [HttpGet("ByMesAno/{anoMes}")] |
| | 55 | | [Authorize("Bearer", Roles = "User, Admin")] |
| | 56 | | [ProducesResponseType(200, Type = typeof(SaldoDto))] |
| | 57 | | [ProducesResponseType(400, Type = typeof(string))] |
| | 58 | | [ProducesResponseType(401)] |
| | 59 | | [ProducesResponseType(403)] |
| | 60 | | public async Task<IActionResult> GetSaldoByMesAno([FromRoute] DateTime anoMes) |
| 2 | 61 | | { |
| | 62 | | try |
| 2 | 63 | | { |
| 2 | 64 | | var saldo = await _saldoBusiness.GetSaldoByMesAno(anoMes, UserIdentity); |
| 1 | 65 | | return Ok(saldo); |
| | 66 | | } |
| 1 | 67 | | catch |
| 1 | 68 | | { |
| 1 | 69 | | return BadRequest("Erro ao gerar saldo!"); |
| | 70 | | } |
| 2 | 71 | | } |
| | 72 | | } |