2024-11-26 00:00:31 +04:00
|
|
|
|
using Contracts.DTO;
|
|
|
|
|
using Contracts.Mappers;
|
|
|
|
|
using Contracts.Repositories;
|
|
|
|
|
using Contracts.SearchModels;
|
|
|
|
|
using Contracts.ViewModels;
|
|
|
|
|
using Services.Support.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace Contracts.Services;
|
|
|
|
|
|
|
|
|
|
public class SpendingGroupService : ISpendingGroupService
|
|
|
|
|
{
|
|
|
|
|
private readonly ISpendingGroupRepo _spendingGroupRepo;
|
|
|
|
|
|
|
|
|
|
public SpendingGroupService(ISpendingGroupRepo spendingGroupRepo)
|
|
|
|
|
{
|
|
|
|
|
_spendingGroupRepo = spendingGroupRepo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<SpendingGroupViewModel> Create(SpendingGroupDto model)
|
|
|
|
|
{
|
|
|
|
|
var group = await _spendingGroupRepo.Create(model);
|
|
|
|
|
return group.ToView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<SpendingGroupViewModel> Delete(SpendingGroupSearch search)
|
|
|
|
|
{
|
|
|
|
|
var group = await _spendingGroupRepo.Delete(search);
|
|
|
|
|
if (group == null)
|
|
|
|
|
{
|
|
|
|
|
throw new EntityNotFoundException("При удалении не получилось найти группу");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return group.ToView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<SpendingGroupViewModel> GetDetails(SpendingGroupSearch search)
|
|
|
|
|
{
|
|
|
|
|
var group = await _spendingGroupRepo.Get(search);
|
|
|
|
|
if (group == null)
|
|
|
|
|
{
|
|
|
|
|
throw new EntityNotFoundException("Не удалось найти группу по таким параметрам");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return group.ToView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<SpendingGroupViewModel>> GetList(SpendingGroupSearch search)
|
|
|
|
|
{
|
|
|
|
|
var groups = await _spendingGroupRepo.GetList(search);
|
2024-11-26 20:23:59 +04:00
|
|
|
|
return groups.Select(x => x.ToView()).ToList();
|
2024-11-26 00:00:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<SpendingGroupViewModel> Update(SpendingGroupDto model)
|
|
|
|
|
{
|
|
|
|
|
var group = await _spendingGroupRepo.Update(model);
|
|
|
|
|
if (group == null)
|
|
|
|
|
{
|
|
|
|
|
throw new EntityNotFoundException("При обновлении не получилось найти группу");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return group.ToView();
|
|
|
|
|
}
|
|
|
|
|
}
|