52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
using Liber_Incantamentum.Application.DTOs.Mage;
|
|
using Liber_Incantamentum.Application.Interfaces.Generals;
|
|
using Liber_Incantamentum.Application.Interfaces.Mappings;
|
|
using Liber_Incantamentum.Application.Interfaces.Validations;
|
|
using Liber_Incantamentum.Domain.Repositories;
|
|
|
|
namespace Liber_Incantamentum.Application.Services.Generals
|
|
{
|
|
public class MageService : IMageService
|
|
{
|
|
private IValidator _validator;
|
|
private IMageRepository _mageRepository;
|
|
private IMapper _mapper;
|
|
public MageService(IMapper mapper, IMageRepository mageRepository, IValidator validator)
|
|
{
|
|
_mapper = mapper;
|
|
_mageRepository = mageRepository;
|
|
_validator = validator;
|
|
}
|
|
|
|
public async Task<bool> AddMageAsync(MageDtoCreate dto)
|
|
{
|
|
_validator.ValidateMageDtoCreate(dto);
|
|
return await _mageRepository.AddMageAsync(_mapper.MapMageDtoCreateToMageEntity(dto));
|
|
}
|
|
|
|
public async Task<bool> DeleteMageAsync(Guid id)
|
|
{
|
|
_validator.ValidateGuid(id);
|
|
return await _mageRepository.DeleteMageAsync(id);
|
|
}
|
|
|
|
public async Task<ICollection<MageDto>?> GetAllMageAsync(MageDtoFilter filter)
|
|
{
|
|
_validator.ValidateMageDtoFilter(filter);
|
|
return _mapper.MapMageEntityCollectionToMageDtoCollection(await _mageRepository.GetAllMageAsync(_mapper.MapMageDtoFilterToMageFilter(filter)));
|
|
}
|
|
|
|
public async Task<MageDto> GetMageByIdAsync(Guid id)
|
|
{
|
|
_validator.ValidateGuid(id);
|
|
return _mapper.mapMageEntityToMageDto(await _mageRepository.GetMageByIdAsync(id));
|
|
}
|
|
|
|
public Task<bool> UpdateMageAsync(MageDtoUpdate dto)
|
|
{
|
|
_validator.ValidateMageDtoUpdate(dto);
|
|
return _mageRepository.UpdateMageAsync(_mapper.MapMageDtoUpdateToMageEntity(dto));
|
|
}
|
|
}
|
|
}
|