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; } public async Task Create(SpendingPlanDto spendingPlan) { var plan = await _spendingPlanRepo.Create(spendingPlan); return plan.ToView(); } public async Task Delete(SpendingPlanSearch search) { var plan = await _spendingPlanRepo.Delete(search); if (plan == null) { throw new EntityNotFoundException("При удалении не получилось найти план"); } return plan.ToView(); } public async Task GetDetails(SpendingPlanSearch search) { var plan = await _spendingPlanRepo.Get(search); if (plan == null) { throw new EntityNotFoundException("Не удалось найти план по таким параметрам"); } return plan.ToView(); } public async Task> GetList(SpendingPlanSearch? search = null) { var plans = await _spendingPlanRepo.GetList(search); return plans.Select(x => x.ToView()).ToList(); } public async Task Update(SpendingPlanDto spendingPlan) { var plan = await _spendingPlanRepo.Update(spendingPlan); if (plan == null) { throw new EntityNotFoundException("При обновлении не получилось найти план"); } return plan.ToView(); } }