58 lines
1.9 KiB
C#

using Liber_Incantamentum.Application.DTOs.Filter;
using Liber_Incantamentum.Application.DTOs.General;
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(SpellDto dto)
{
if (_validator.ValidateSpellDto(dto))
{
await _spellRepository.AddSpellAsync(_mapper.MapSpellDtoToSpellEntity(dto));
}
return false;
}
public async Task<bool> DeleteSpellAsync(Guid id)
{
if (_validator.ValidateGuid(id))
{
await _spellRepository.DeleteSpellAsync(id);
}
return false;
}
public async Task<ICollection<SpellDto>?> GetAllSpellAsync(SpellDtoFilter filter)
{
if (_validator.ValidateSpellDtoFilter(filter))
{
await _spellRepository.GetAllSpellAsync(_mapper.MapSpellDtoFilterToSpellFilterEntity(filter));
}
return null;
}
public async Task<bool> UpdateSpellAsync(SpellDtoFilter filter)
{
if (_validator.ValidateSpellDtoFilter(filter))
{
await _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoFilterToSpellFilterEntity(filter));
}
return false;
}
}
}