add: контроллер групп расходов
This commit is contained in:
parent
6e4e47dc59
commit
078b469752
@ -7,7 +7,7 @@ namespace Contracts.Services;
|
|||||||
public interface ISpendingGroupService
|
public interface ISpendingGroupService
|
||||||
{
|
{
|
||||||
Task<SpendingGroupViewModel> GetDetails(SpendingGroupSearch search);
|
Task<SpendingGroupViewModel> GetDetails(SpendingGroupSearch search);
|
||||||
Task<IEnumerable<SpendingGroupViewModel>> GetList(SpendingGroupSearch search);
|
Task<IEnumerable<SpendingGroupViewModel>> GetList(SpendingGroupSearch? search = null);
|
||||||
Task<SpendingGroupViewModel> Create(SpendingGroupDto model);
|
Task<SpendingGroupViewModel> Create(SpendingGroupDto model);
|
||||||
Task<SpendingGroupViewModel> Update(SpendingGroupDto model);
|
Task<SpendingGroupViewModel> Update(SpendingGroupDto model);
|
||||||
Task<SpendingGroupViewModel> Delete(SpendingGroupSearch search);
|
Task<SpendingGroupViewModel> Delete(SpendingGroupSearch search);
|
||||||
|
118
back/Controllers/Controllers/SpendingGroupController.cs
Normal file
118
back/Controllers/Controllers/SpendingGroupController.cs
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
namespace Controllers.Extensions;
|
||||||
|
|
||||||
|
using Contracts.DTO;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
using Contracts.Services;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Services.Support.Exceptions;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class SpendingGroupController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ISpendingGroupService _spendingGroupService;
|
||||||
|
|
||||||
|
public SpendingGroupController(ISpendingGroupService spendingGroupService)
|
||||||
|
{
|
||||||
|
_spendingGroupService = spendingGroupService;
|
||||||
|
}
|
||||||
|
[HttpGet("details")]
|
||||||
|
public async Task<ActionResult<SpendingGroupViewModel>> GetSpendingGroup(
|
||||||
|
[FromQuery] SpendingGroupSearch search)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var group = await _spendingGroupService.GetDetails(search);
|
||||||
|
return Ok(group);
|
||||||
|
}
|
||||||
|
catch (EntityNotFoundException ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<List<SpendingGroupViewModel>>> GetSpendingGroups()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var groups = await _spendingGroupService.GetList();
|
||||||
|
return Ok(groups);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("filter")]
|
||||||
|
public async Task<ActionResult<List<SpendingGroupViewModel>>> GetSpendingGroups(
|
||||||
|
[FromQuery] SpendingGroupSearch search)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var groups = await _spendingGroupService.GetList(search);
|
||||||
|
return Ok(groups);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult<SpendingGroupViewModel>> CreateSpendingGroup(
|
||||||
|
[FromBody] SpendingGroupDto dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var group = await _spendingGroupService.Create(dto);
|
||||||
|
return CreatedAtAction(nameof(GetSpendingGroup), new { id = group.Id }, group);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch]
|
||||||
|
public async Task<ActionResult<SpendingGroupViewModel>> UpdateSpendingGroup([FromBody] SpendingGroupDto dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var group = await _spendingGroupService.Update(dto);
|
||||||
|
return Ok(group);
|
||||||
|
}
|
||||||
|
catch (EntityNotFoundException ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete]
|
||||||
|
public async Task<ActionResult> DeleteSpendingGroup([FromQuery] SpendingGroupSearch search)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var group = await _spendingGroupService.Delete(search);
|
||||||
|
return Ok(group);
|
||||||
|
}
|
||||||
|
catch (EntityNotFoundException ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user