add: контроллеры записей изменения баланса

This commit is contained in:
mfnefd 2024-11-26 22:46:38 +04:00
parent f94d4ed246
commit 3684f1479c
4 changed files with 98 additions and 1 deletions

View File

@ -0,0 +1,86 @@
using Contracts.DTO;
using Contracts.SearchModels;
using Contracts.Services;
using Contracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Services.Support.Exceptions;
namespace Controllers.Controllers;
[Route("api/[controller]")]
[ApiController]
public class ChangeRecordController : ControllerBase
{
private readonly IChangeRecordService _changeRecordService;
public ChangeRecordController(IChangeRecordService changeRecordService)
{
_changeRecordService = changeRecordService;
}
[HttpPost]
public async Task<ActionResult<ChangeRecordViewModel>> CreateChangeRecord(
[FromBody] ChangeRecordDto dto)
{
try
{
var record = await _changeRecordService.Create(dto);
return CreatedAtAction(nameof(GetChangeRecords), record);
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
[HttpGet]
public async Task<ActionResult<IEnumerable<ChangeRecordViewModel>>> GetChangeRecords(
[FromQuery] ChangeRecordSearch search)
{
try
{
var records = await _changeRecordService.GetList(search);
return Ok(records);
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
[HttpPatch]
public async Task<ActionResult<ChangeRecordViewModel>> UpdateChangeRecord([FromBody] ChangeRecordDto dto)
{
try
{
var record = await _changeRecordService.Update(dto);
return Ok(record);
}
catch (EntityNotFoundException ex)
{
return NotFound(ex.Message);
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
[HttpDelete]
public async Task<ActionResult> DeleteChangeRecord([FromQuery] ChangeRecordSearch search)
{
try
{
var record = await _changeRecordService.Delete(search);
return Ok(record);
}
catch (EntityNotFoundException ex)
{
return NotFound(ex.Message);
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
}

View File

@ -17,12 +17,16 @@ public class SpendingGroupController : ControllerBase
{
_spendingGroupService = spendingGroupService;
}
[HttpGet("details")]
[HttpGet("{id}")]
public async Task<ActionResult<SpendingGroupViewModel>> GetSpendingGroup(
Guid id,
[FromQuery] SpendingGroupSearch search)
{
try
{
search ??= new();
search.Id = id;
var group = await _spendingGroupService.GetDetails(search);
return Ok(group);
}
@ -74,6 +78,10 @@ public class SpendingGroupController : ControllerBase
var group = await _spendingGroupService.Create(dto);
return CreatedAtAction(nameof(GetSpendingGroup), new { id = group.Id }, group);
}
catch (EntityNotFoundException ex)
{
return NotFound(ex.Message);
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);

View File

@ -11,5 +11,7 @@ public static class AddDomainServicesExtension
services.AddTransient<IUserService, UserService>();
services.AddTransient<ISpendingGroupService, SpendingGroupService>();
services.AddTransient<IChangeRecordService, ChangeRecordService>();
}
}

View File

@ -11,5 +11,6 @@ public static class AddReposExtension
{
services.AddTransient<IUserRepo, UserRepo>();
services.AddTransient<ISpendingGroupRepo, SpendingGroupRepo>();
services.AddTransient<IChangeRecordRepo, ChangeRecordRepo>();
}
}