0.1.0 #2
63
back/Services/Domain/SpendingGroupService.cs
Normal file
63
back/Services/Domain/SpendingGroupService.cs
Normal file
@ -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<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);
|
||||||
|
return groups.Select(x => x.ToView());
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<SpendingGroupViewModel> Update(SpendingGroupDto model)
|
||||||
|
{
|
||||||
|
var group = await _spendingGroupRepo.Update(model);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
throw new EntityNotFoundException("При обновлении не получилось найти группу");
|
||||||
|
}
|
||||||
|
|
||||||
|
return group.ToView();
|
||||||
|
}
|
||||||
|
}
|
10
back/Services/Support/Exceptions/EntityNotFoundException.cs
Normal file
10
back/Services/Support/Exceptions/EntityNotFoundException.cs
Normal file
@ -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) { }
|
||||||
|
|
||||||
|
}
|
@ -2,10 +2,11 @@ using Contracts.SearchModels;
|
|||||||
|
|
||||||
namespace Services.Support.Exceptions;
|
namespace Services.Support.Exceptions;
|
||||||
|
|
||||||
public class UserNotFoundException : Exception
|
public class UserNotFoundException : EntityNotFoundException
|
||||||
{
|
{
|
||||||
public UserNotFoundException(string message)
|
public UserNotFoundException(string message)
|
||||||
: base(message) { }
|
: base(message) { }
|
||||||
public UserNotFoundException(string message, Exception innerException)
|
public UserNotFoundException(string message, Exception innerException)
|
||||||
: base(message, innerException) { }
|
: base(message, innerException) { }
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user