From 3f7687454705836dea181ec167d606b6176d9d41 Mon Sep 17 00:00:00 2001 From: mfnefd Date: Tue, 26 Nov 2024 00:00:31 +0400 Subject: [PATCH] =?UTF-8?q?add:=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=20?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=BF=D0=BF=20=D1=80=D0=B0=D1=81=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/Services/Domain/SpendingGroupService.cs | 63 +++++++++++++++++++ .../Exceptions/EntityNotFoundException.cs | 10 +++ .../Exceptions/UserNotFoundException.cs | 3 +- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 back/Services/Domain/SpendingGroupService.cs create mode 100644 back/Services/Support/Exceptions/EntityNotFoundException.cs diff --git a/back/Services/Domain/SpendingGroupService.cs b/back/Services/Domain/SpendingGroupService.cs new file mode 100644 index 0000000..005ee40 --- /dev/null +++ b/back/Services/Domain/SpendingGroupService.cs @@ -0,0 +1,63 @@ +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 Create(SpendingGroupDto model) + { + var group = await _spendingGroupRepo.Create(model); + return group.ToView(); + } + + public async Task Delete(SpendingGroupSearch search) + { + var group = await _spendingGroupRepo.Delete(search); + if (group == null) + { + throw new EntityNotFoundException("При удалении не получилось найти группу"); + } + + return group.ToView(); + } + + public async Task GetDetails(SpendingGroupSearch search) + { + var group = await _spendingGroupRepo.Get(search); + if (group == null) + { + throw new EntityNotFoundException("Не удалось найти группу по таким параметрам"); + } + + return group.ToView(); + } + + public async Task> GetList(SpendingGroupSearch search) + { + var groups = await _spendingGroupRepo.GetList(search); + return groups.Select(x => x.ToView()); + } + + public async Task Update(SpendingGroupDto model) + { + var group = await _spendingGroupRepo.Update(model); + if (group == null) + { + throw new EntityNotFoundException("При обновлении не получилось найти группу"); + } + + return group.ToView(); + } +} diff --git a/back/Services/Support/Exceptions/EntityNotFoundException.cs b/back/Services/Support/Exceptions/EntityNotFoundException.cs new file mode 100644 index 0000000..957b0b3 --- /dev/null +++ b/back/Services/Support/Exceptions/EntityNotFoundException.cs @@ -0,0 +1,10 @@ +namespace Services.Support.Exceptions; + +public class EntityNotFoundException : Exception +{ + public EntityNotFoundException(string message) + : base(message) { } + public EntityNotFoundException(string message, Exception innerException) + : base(message, innerException) { } + +} \ No newline at end of file diff --git a/back/Services/Support/Exceptions/UserNotFoundException.cs b/back/Services/Support/Exceptions/UserNotFoundException.cs index df152a1..77b2297 100644 --- a/back/Services/Support/Exceptions/UserNotFoundException.cs +++ b/back/Services/Support/Exceptions/UserNotFoundException.cs @@ -2,10 +2,11 @@ using Contracts.SearchModels; namespace Services.Support.Exceptions; -public class UserNotFoundException : Exception +public class UserNotFoundException : EntityNotFoundException { public UserNotFoundException(string message) : base(message) { } public UserNotFoundException(string message, Exception innerException) : base(message, innerException) { } + } \ No newline at end of file