2025-08-02 18:56:44 +02:00

52 lines
2.0 KiB
C#

using Liber_Incantamentum.Application.DTOs.Mage;
using Liber_Incantamentum.Application.DTOs.Spell;
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 SpellService : ISpellService
{
private IValidator _validator;
private ISpellRepository _spellRepository;
private IMapper _mapper;
public SpellService(IValidator validator, ISpellRepository spellRepository, IMapper mapper)
{
_mapper = mapper;
_validator = validator;
_spellRepository = spellRepository;
}
public async Task<bool> AddSpellAsync(SpellDtoCreate dto)
{
_validator.ValidateSpellDtoCreate(dto);
return await _spellRepository.AddSpellAsync(_mapper.MapSpellDtoCreateToSpellEntity(dto));
}
public async Task<bool> DeleteSpellAsync(Guid id)
{
_validator.ValidateGuid(id);
return await _spellRepository.DeleteSpellAsync(id);
}
public async Task<ICollection<SpellDto>?> GetAllSpellAsync(SpellDtoFilter filter)
{
_validator.ValidateSpellDtoFilter(filter);
return _mapper.MapSpellEntityCollectionToSpellDtoCollection(await _spellRepository.GetAllSpellAsync(_mapper.MapSpellDtoFilterToSpellFilter(filter)));
}
public async Task<SpellDto> GetSpellByIdAsync(Guid id)
{
_validator.ValidateGuid(id);
return _mapper.mapSpellEntityToSpellDto(await _spellRepository.GetSpellByIdAsync(id));
}
public Task<bool> UpdateSpellAsync(SpellDtoUpdate dto)
{
_validator.ValidateSpellDtoUpdate(dto);
return _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoUpdateToSpellEntity(dto));
}
}
}