2024-11-27 02:13:01 +04:00
|
|
|
|
using Contracts.DTO;
|
|
|
|
|
using Contracts.Mappers;
|
|
|
|
|
using Contracts.Repositories;
|
|
|
|
|
using Contracts.SearchModels;
|
|
|
|
|
using Contracts.Services;
|
|
|
|
|
using Contracts.ViewModels;
|
|
|
|
|
using Services.Support.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace Services.Domain;
|
|
|
|
|
|
|
|
|
|
public class SpendingPlanService : ISpendingPlanService
|
|
|
|
|
{
|
|
|
|
|
private readonly ISpendingPlanRepo _spendingPlanRepo;
|
|
|
|
|
|
|
|
|
|
public SpendingPlanService(ISpendingPlanRepo spendingPlanRepo)
|
|
|
|
|
{
|
|
|
|
|
_spendingPlanRepo = spendingPlanRepo;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 02:20:17 +04:00
|
|
|
|
public async Task<SpendingPlanViewModel> Create(SpendingPlanDto spendingPlan)
|
2024-11-27 02:13:01 +04:00
|
|
|
|
{
|
|
|
|
|
var plan = await _spendingPlanRepo.Create(spendingPlan);
|
|
|
|
|
return plan.ToView();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 02:20:17 +04:00
|
|
|
|
public async Task<SpendingPlanViewModel> Delete(SpendingPlanSearch search)
|
2024-11-27 02:13:01 +04:00
|
|
|
|
{
|
|
|
|
|
var plan = await _spendingPlanRepo.Delete(search);
|
|
|
|
|
if (plan == null)
|
|
|
|
|
{
|
|
|
|
|
throw new EntityNotFoundException("При удалении не получилось найти план");
|
|
|
|
|
}
|
|
|
|
|
return plan.ToView();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 02:20:17 +04:00
|
|
|
|
public async Task<SpendingPlanViewModel> GetDetails(SpendingPlanSearch search)
|
2024-11-27 02:13:01 +04:00
|
|
|
|
{
|
|
|
|
|
var plan = await _spendingPlanRepo.Get(search);
|
|
|
|
|
if (plan == null)
|
|
|
|
|
{
|
|
|
|
|
throw new EntityNotFoundException("Не удалось найти план по таким параметрам");
|
|
|
|
|
}
|
|
|
|
|
return plan.ToView();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 02:20:17 +04:00
|
|
|
|
public async Task<IEnumerable<SpendingPlanViewModel>> GetList(SpendingPlanSearch? search = null)
|
2024-11-27 02:13:01 +04:00
|
|
|
|
{
|
|
|
|
|
var plans = await _spendingPlanRepo.GetList(search);
|
|
|
|
|
return plans.Select(x => x.ToView()).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 02:20:17 +04:00
|
|
|
|
public async Task<SpendingPlanViewModel> Update(SpendingPlanDto spendingPlan)
|
2024-11-27 02:13:01 +04:00
|
|
|
|
{
|
|
|
|
|
var plan = await _spendingPlanRepo.Update(spendingPlan);
|
|
|
|
|
if (plan == null)
|
|
|
|
|
{
|
|
|
|
|
throw new EntityNotFoundException("При обновлении не получилось найти план");
|
|
|
|
|
}
|
|
|
|
|
return plan.ToView();
|
|
|
|
|
}
|
|
|
|
|
}
|