Maj
This commit is contained in:
parent
5cd762fc3d
commit
39b8312807
13
Liber_Incantamentum.Application/DTOs/Mage/MageDto.cs
Normal file
13
Liber_Incantamentum.Application/DTOs/Mage/MageDto.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using Liber_Incantamentum.Application.DTOs.Spell;
|
||||||
|
|
||||||
|
namespace Liber_Incantamentum.Application.DTOs.Mage
|
||||||
|
{
|
||||||
|
public class MageDto
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public required string Rank { get; set; }
|
||||||
|
public required string Specialisation { get; set; }
|
||||||
|
public ICollection<SpellDto> Spells { get; set; } = new List<SpellDto>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
namespace Liber_Incantamentum.Application.DTOs.Mage
|
||||||
|
{
|
||||||
|
public class MageDtoCreate
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public required string Rank { get; set; }
|
||||||
|
public required string Specialisation { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
namespace Liber_Incantamentum.Application.DTOs.Filter
|
namespace Liber_Incantamentum.Application.DTOs.Mage
|
||||||
{
|
{
|
||||||
public class MageDtoFilter
|
public class MageDtoFilter
|
||||||
{
|
{
|
||||||
@ -1,6 +1,6 @@
|
|||||||
namespace Liber_Incantamentum.Application.DTOs.General
|
namespace Liber_Incantamentum.Application.DTOs.Mage
|
||||||
{
|
{
|
||||||
public class MageDto
|
public class MageDtoUpdate
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
@ -1,4 +1,4 @@
|
|||||||
namespace Liber_Incantamentum.Application.DTOs.General
|
namespace Liber_Incantamentum.Application.DTOs.Spell
|
||||||
{
|
{
|
||||||
public class SpellDto
|
public class SpellDto
|
||||||
{
|
{
|
||||||
@ -7,6 +7,6 @@
|
|||||||
public required string Description { get; set; }
|
public required string Description { get; set; }
|
||||||
public required string Type { get; set; }
|
public required string Type { get; set; }
|
||||||
public required DateTime CreationDate { get; set; }
|
public required DateTime CreationDate { get; set; }
|
||||||
public required MageDto Mage { get; set; }
|
public Guid MageId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11
Liber_Incantamentum.Application/DTOs/Spell/SpellDtoCreate.cs
Normal file
11
Liber_Incantamentum.Application/DTOs/Spell/SpellDtoCreate.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace Liber_Incantamentum.Application.DTOs.Spell
|
||||||
|
{
|
||||||
|
public class SpellDtoCreate
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public required string Description { get; set; }
|
||||||
|
public required string Type { get; set; }
|
||||||
|
public required DateTime CreationDate { get; set; }
|
||||||
|
public Guid MageId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
namespace Liber_Incantamentum.Application.DTOs.Filter
|
namespace Liber_Incantamentum.Application.DTOs.Spell
|
||||||
{
|
{
|
||||||
public class SpellDtoFilter
|
public class SpellDtoFilter
|
||||||
{
|
{
|
||||||
public Guid? Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
public string? Type { get; set; }
|
public string? Type { get; set; }
|
||||||
public DateTime? CreationDate { get; set; }
|
public DateTime? CreationDate { get; set; }
|
||||||
public MageDtoFilter? Mage { get; set; }
|
public Guid? MageId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
12
Liber_Incantamentum.Application/DTOs/Spell/SpellDtoUpdate.cs
Normal file
12
Liber_Incantamentum.Application/DTOs/Spell/SpellDtoUpdate.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace Liber_Incantamentum.Application.DTOs.Spell
|
||||||
|
{
|
||||||
|
public class SpellDtoUpdate
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public required string Description { get; set; }
|
||||||
|
public required string Type { get; set; }
|
||||||
|
public required DateTime CreationDate { get; set; }
|
||||||
|
public Guid MageId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,13 +1,13 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.DTOs.Mage;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
|
||||||
|
|
||||||
namespace Liber_Incantamentum.Application.Interfaces.Generals
|
namespace Liber_Incantamentum.Application.Interfaces.Generals
|
||||||
{
|
{
|
||||||
public interface IMageService
|
public interface IMageService
|
||||||
{
|
{
|
||||||
Task<ICollection<MageDto>?> GetAllMageAsync(MageDtoFilter filter);
|
Task<ICollection<MageDto>?> GetAllMageAsync(MageDtoFilter filter);
|
||||||
Task<bool> UpdateMageAsync(MageDtoFilter dto);
|
Task<bool> UpdateMageAsync(MageDtoUpdate dto);
|
||||||
Task<bool> DeleteMageAsync(Guid id);
|
Task<bool> DeleteMageAsync(Guid id);
|
||||||
Task<bool> AddMageAsync(MageDto dto);
|
Task<bool> AddMageAsync(MageDtoCreate dto);
|
||||||
|
Task<MageDto> GetMageByIdAsync(Guid id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.DTOs.Mage;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
using Liber_Incantamentum.Application.DTOs.Spell;
|
||||||
|
|
||||||
namespace Liber_Incantamentum.Application.Interfaces.Generals
|
namespace Liber_Incantamentum.Application.Interfaces.Generals
|
||||||
{
|
{
|
||||||
public interface ISpellService
|
public interface ISpellService
|
||||||
{
|
{
|
||||||
Task<ICollection<SpellDto>?> GetAllSpellAsync(SpellDtoFilter filter);
|
Task<ICollection<SpellDto>?> GetAllSpellAsync(SpellDtoFilter filter);
|
||||||
Task<bool> UpdateSpellAsync(SpellDtoFilter dto);
|
Task<bool> UpdateSpellAsync(SpellDtoUpdate dto);
|
||||||
Task<bool> DeleteSpellAsync(Guid id);
|
Task<bool> DeleteSpellAsync(Guid id);
|
||||||
Task<bool> AddSpellAsync(SpellDto dto);
|
Task<bool> AddSpellAsync(SpellDtoCreate dto);
|
||||||
|
Task<SpellDto> GetSpellByIdAsync(Guid id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.DTOs.Mage;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
using Liber_Incantamentum.Application.DTOs.Spell;
|
||||||
using Liber_Incantamentum.Domain.Entities;
|
using Liber_Incantamentum.Domain.Entities;
|
||||||
using Liber_Incantamentum.Domain.Filter;
|
using Liber_Incantamentum.Domain.Filter;
|
||||||
|
|
||||||
@ -7,10 +7,15 @@ namespace Liber_Incantamentum.Application.Interfaces.Mappings
|
|||||||
{
|
{
|
||||||
public interface IMapper
|
public interface IMapper
|
||||||
{
|
{
|
||||||
MageFilter MapMageDtoFilterToMageFilterEntity(MageDtoFilter filter);
|
Mage MapMageDtoCreateToMageEntity(MageDtoCreate value);
|
||||||
Mage MapMageDtoToMageEntity(MageDto dto);
|
MageFilter MapMageDtoFilterToMageFilter(MageDtoFilter value);
|
||||||
ICollection<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage>? task);
|
Mage MapMageDtoUpdateToMageEntity(MageDtoUpdate value);
|
||||||
SpellFilter MapSpellDtoFilterToSpellFilterEntity(SpellDtoFilter dto);
|
ICollection<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage>? value);
|
||||||
Spell MapSpellDtoToSpellEntity(SpellDto dto);
|
MageDto mapMageEntityToMageDto(Mage mage);
|
||||||
|
Spell MapSpellDtoCreateToSpellEntity(SpellDtoCreate value);
|
||||||
|
SpellFilter MapSpellDtoFilterToSpellFilter(SpellDtoFilter value);
|
||||||
|
Spell MapSpellDtoUpdateToSpellEntity(SpellDtoUpdate value);
|
||||||
|
ICollection<SpellDto>? MapSpellEntityCollectionToSpellDtoCollection(ICollection<Spell>? value);
|
||||||
|
SpellDto mapSpellEntityToSpellDto(Spell spell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,18 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.DTOs.Mage;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
using Liber_Incantamentum.Application.DTOs.Spell;
|
||||||
|
|
||||||
namespace Liber_Incantamentum.Application.Interfaces.Validations
|
namespace Liber_Incantamentum.Application.Interfaces.Validations
|
||||||
{
|
{
|
||||||
public interface IValidator
|
public interface IValidator
|
||||||
{
|
{
|
||||||
void ValidateGuid(Guid id);
|
void ValidateGuid(Guid value);
|
||||||
void ValidateMageDto(MageDto dto);
|
void ValidateMageDto(MageDto value);
|
||||||
void ValidateMageDtoFilter(MageDtoFilter filter);
|
void ValidateMageDtoCreate(MageDtoCreate value);
|
||||||
void ValidateSpellDto(SpellDto dto);
|
void ValidateMageDtoUpdate(MageDtoUpdate value);
|
||||||
void ValidateSpellDtoFilter(SpellDtoFilter filter);
|
void ValidateMageDtoFilter(MageDtoFilter value);
|
||||||
|
void ValidateSpellDto(SpellDto value);
|
||||||
|
void ValidateSpellDtoCreate(SpellDtoCreate value);
|
||||||
|
void ValidateSpellDtoUpdate(SpellDtoUpdate value);
|
||||||
|
void ValidateSpellDtoFilter(SpellDtoFilter value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.DTOs.Mage;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
|
||||||
using Liber_Incantamentum.Application.Interfaces.Generals;
|
using Liber_Incantamentum.Application.Interfaces.Generals;
|
||||||
using Liber_Incantamentum.Application.Interfaces.Mappings;
|
using Liber_Incantamentum.Application.Interfaces.Mappings;
|
||||||
using Liber_Incantamentum.Application.Interfaces.Validations;
|
using Liber_Incantamentum.Application.Interfaces.Validations;
|
||||||
@ -18,10 +17,11 @@ namespace Liber_Incantamentum.Application.Services.Generals
|
|||||||
_mageRepository = mageRepository;
|
_mageRepository = mageRepository;
|
||||||
_validator = validator;
|
_validator = validator;
|
||||||
}
|
}
|
||||||
public async Task<bool> AddMageAsync(MageDto dto)
|
|
||||||
|
public async Task<bool> AddMageAsync(MageDtoCreate dto)
|
||||||
{
|
{
|
||||||
_validator.ValidateMageDto(dto);
|
_validator.ValidateMageDtoCreate(dto);
|
||||||
return await _mageRepository.AddMageAsync(_mapper.MapMageDtoToMageEntity(dto));
|
return await _mageRepository.AddMageAsync(_mapper.MapMageDtoCreateToMageEntity(dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> DeleteMageAsync(Guid id)
|
public async Task<bool> DeleteMageAsync(Guid id)
|
||||||
@ -33,14 +33,19 @@ namespace Liber_Incantamentum.Application.Services.Generals
|
|||||||
public async Task<ICollection<MageDto>?> GetAllMageAsync(MageDtoFilter filter)
|
public async Task<ICollection<MageDto>?> GetAllMageAsync(MageDtoFilter filter)
|
||||||
{
|
{
|
||||||
_validator.ValidateMageDtoFilter(filter);
|
_validator.ValidateMageDtoFilter(filter);
|
||||||
return await _mapper.MapMageEntityCollectionToMageDtoCollection(_mageRepository.GetAllMageAsync(_mapper.MapMageDtoFilterToMageFilterEntity(filter)));
|
return _mapper.MapMageEntityCollectionToMageDtoCollection(await _mageRepository.GetAllMageAsync(_mapper.MapMageDtoFilterToMageFilter(filter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> UpdateMageAsync(MageDtoFilter dto)
|
public async Task<MageDto> GetMageByIdAsync(Guid id)
|
||||||
{
|
{
|
||||||
_validator.ValidateMageDtoFilter(dto);
|
_validator.ValidateGuid(id);
|
||||||
await _mageRepository.UpdateMageAsync(_mapper.MapMageDtoFilterToMageFilterEntity(dto));
|
return _mapper.mapMageEntityToMageDto(await _mageRepository.GetMageByIdAsync(id));
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
public Task<bool> UpdateMageAsync(MageDtoUpdate dto)
|
||||||
|
{
|
||||||
|
_validator.ValidateMageDtoUpdate(dto);
|
||||||
|
return _mageRepository.UpdateMageAsync(_mapper.MapMageDtoUpdateToMageEntity(dto));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.DTOs.Mage;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
using Liber_Incantamentum.Application.DTOs.Spell;
|
||||||
using Liber_Incantamentum.Application.Interfaces.Generals;
|
using Liber_Incantamentum.Application.Interfaces.Generals;
|
||||||
using Liber_Incantamentum.Application.Interfaces.Mappings;
|
using Liber_Incantamentum.Application.Interfaces.Mappings;
|
||||||
using Liber_Incantamentum.Application.Interfaces.Validations;
|
using Liber_Incantamentum.Application.Interfaces.Validations;
|
||||||
@ -18,40 +18,34 @@ namespace Liber_Incantamentum.Application.Services.Generals
|
|||||||
_validator = validator;
|
_validator = validator;
|
||||||
_spellRepository = spellRepository;
|
_spellRepository = spellRepository;
|
||||||
}
|
}
|
||||||
public async Task<bool> AddSpellAsync(SpellDto dto)
|
public async Task<bool> AddSpellAsync(SpellDtoCreate dto)
|
||||||
{
|
{
|
||||||
if (_validator.ValidateSpellDto(dto))
|
_validator.ValidateSpellDtoCreate(dto);
|
||||||
{
|
return await _spellRepository.AddSpellAsync(_mapper.MapSpellDtoCreateToSpellEntity(dto));
|
||||||
await _spellRepository.AddSpellAsync(_mapper.MapSpellDtoToSpellEntity(dto));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> DeleteSpellAsync(Guid id)
|
public async Task<bool> DeleteSpellAsync(Guid id)
|
||||||
{
|
{
|
||||||
if (_validator.ValidateGuid(id))
|
_validator.ValidateGuid(id);
|
||||||
{
|
return await _spellRepository.DeleteSpellAsync(id);
|
||||||
await _spellRepository.DeleteSpellAsync(id);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ICollection<SpellDto>?> GetAllSpellAsync(SpellDtoFilter filter)
|
public async Task<ICollection<SpellDto>?> GetAllSpellAsync(SpellDtoFilter filter)
|
||||||
{
|
{
|
||||||
if (_validator.ValidateSpellDtoFilter(filter))
|
_validator.ValidateSpellDtoFilter(filter);
|
||||||
{
|
return _mapper.MapSpellEntityCollectionToSpellDtoCollection(await _spellRepository.GetAllSpellAsync(_mapper.MapSpellDtoFilterToSpellFilter(filter)));
|
||||||
await _spellRepository.GetAllSpellAsync(_mapper.MapSpellDtoFilterToSpellFilterEntity(filter));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> UpdateSpellAsync(SpellDtoFilter filter)
|
public async Task<SpellDto> GetSpellByIdAsync(Guid id)
|
||||||
{
|
{
|
||||||
if (_validator.ValidateSpellDtoFilter(filter))
|
_validator.ValidateGuid(id);
|
||||||
{
|
return _mapper.mapSpellEntityToSpellDto(await _spellRepository.GetSpellByIdAsync(id));
|
||||||
await _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoFilterToSpellFilterEntity(filter));
|
}
|
||||||
}
|
|
||||||
return false;
|
public Task<bool> UpdateSpellAsync(SpellDtoUpdate dto)
|
||||||
|
{
|
||||||
|
_validator.ValidateSpellDtoUpdate(dto);
|
||||||
|
return _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoUpdateToSpellEntity(dto));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,51 +1,48 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.DTOs.Mage;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
using Liber_Incantamentum.Application.DTOs.Spell;
|
||||||
using Liber_Incantamentum.Application.Interfaces.Mappings;
|
using Liber_Incantamentum.Application.Interfaces.Mappings;
|
||||||
using Liber_Incantamentum.Domain.Entities;
|
using Liber_Incantamentum.Domain.Entities;
|
||||||
using Liber_Incantamentum.Domain.Filter;
|
using Liber_Incantamentum.Domain.Filter;
|
||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace Liber_Incantamentum.Application.Services.Mappings
|
namespace Liber_Incantamentum.Application.Services.Mappings
|
||||||
{
|
{
|
||||||
public class Mapper : IMapper
|
public class Mapper : IMapper
|
||||||
{
|
{
|
||||||
public MageFilter MapMageDtoFilterToMageFilterEntity(MageDtoFilter filter)
|
public Mage MapMageDtoCreateToMageEntity(MageDtoCreate value)
|
||||||
{
|
{
|
||||||
MageFilter entity = new MageFilter()
|
return new Mage()
|
||||||
{
|
{
|
||||||
Id = filter.Id,
|
Name = value.Name,
|
||||||
Name = filter.Name,
|
Rank = value.Rank,
|
||||||
Rank = filter.Rank,
|
Specialisation = value.Specialisation
|
||||||
Specialisation = filter.Specialisation
|
|
||||||
};
|
};
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mage MapMageDtoToMageEntity(MageDto dto)
|
public MageFilter MapMageDtoFilterToMageFilter(MageDtoFilter value)
|
||||||
{
|
{
|
||||||
Mage entity = new Mage()
|
return new MageFilter()
|
||||||
{
|
{
|
||||||
Name = dto.Name,
|
Id = value.Id,
|
||||||
Rank = dto.Rank,
|
Name = value.Name,
|
||||||
Specialisation = dto.Specialisation
|
Rank = value.Rank,
|
||||||
|
Specialisation = value.Specialisation
|
||||||
};
|
};
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
public MageDto MapMageEntityToMageDto(Mage entity)
|
|
||||||
{
|
|
||||||
MageDto dto = new MageDto()
|
|
||||||
{
|
|
||||||
Name = entity.Name,
|
|
||||||
Rank = entity.Rank,
|
|
||||||
Specialisation = entity.Specialisation
|
|
||||||
};
|
|
||||||
return dto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage> collection)
|
public Mage MapMageDtoUpdateToMageEntity(MageDtoUpdate value)
|
||||||
{
|
{
|
||||||
ICollection<MageDto> MageDtoCollection = new List<MageDto>();
|
return new Mage()
|
||||||
foreach(var entity in collection)
|
{
|
||||||
|
Name = value.Name,
|
||||||
|
Rank = value.Rank,
|
||||||
|
Specialisation = value.Specialisation
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICollection<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage>? value)
|
||||||
|
{
|
||||||
|
var mageDtoCollection = new List<MageDto>();
|
||||||
|
foreach (var entity in value)
|
||||||
{
|
{
|
||||||
MageDto dto = new MageDto()
|
MageDto dto = new MageDto()
|
||||||
{
|
{
|
||||||
@ -54,55 +51,91 @@ namespace Liber_Incantamentum.Application.Services.Mappings
|
|||||||
Rank = entity.Rank,
|
Rank = entity.Rank,
|
||||||
Specialisation = entity.Specialisation
|
Specialisation = entity.Specialisation
|
||||||
};
|
};
|
||||||
MageDtoCollection.Add(dto);
|
|
||||||
|
mageDtoCollection.Add(dto);
|
||||||
}
|
}
|
||||||
return MageDtoCollection;
|
|
||||||
|
return mageDtoCollection;
|
||||||
}
|
}
|
||||||
public ICollection<SpellDto>? MapSpellEntityCollectionToSpellDtoCollection(ICollection<Spell> collection)
|
|
||||||
|
public MageDto mapMageEntityToMageDto(Mage mage)
|
||||||
{
|
{
|
||||||
ICollection<SpellDto> SpellDtoCollection = new List<SpellDto>();
|
return new MageDto()
|
||||||
foreach (var entity in collection)
|
|
||||||
{
|
{
|
||||||
SpellDto dto = new SpellDto()
|
Id = mage.Id,
|
||||||
|
Name = mage.Name,
|
||||||
|
Rank = mage.Rank,
|
||||||
|
Specialisation = mage.Specialisation
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Spell MapSpellDtoCreateToSpellEntity(SpellDtoCreate value)
|
||||||
|
{
|
||||||
|
return new Spell()
|
||||||
|
{
|
||||||
|
Name = value.Name,
|
||||||
|
Description = value.Description,
|
||||||
|
Type = value.Type,
|
||||||
|
CreationDate = value.CreationDate,
|
||||||
|
MageId = value.MageId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpellFilter MapSpellDtoFilterToSpellFilter(SpellDtoFilter value)
|
||||||
|
{
|
||||||
|
return new SpellFilter()
|
||||||
|
{
|
||||||
|
Id = value.Id,
|
||||||
|
Name = value.Name,
|
||||||
|
Description = value.Description,
|
||||||
|
Type = value.Type,
|
||||||
|
CreationDate = value.CreationDate,
|
||||||
|
MageId = value.MageId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Spell MapSpellDtoUpdateToSpellEntity(SpellDtoUpdate value)
|
||||||
|
{
|
||||||
|
return new Spell()
|
||||||
|
{
|
||||||
|
Name = value.Name,
|
||||||
|
Description = value.Description,
|
||||||
|
Type = value.Type,
|
||||||
|
CreationDate = value.CreationDate,
|
||||||
|
MageId = value.MageId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICollection<SpellDto>? MapSpellEntityCollectionToSpellDtoCollection(ICollection<Spell>? value)
|
||||||
|
{
|
||||||
|
var spellDtoCollection = new List<SpellDto>();
|
||||||
|
foreach (var x in value)
|
||||||
|
{
|
||||||
|
var dto = new SpellDto()
|
||||||
{
|
{
|
||||||
Id = entity.Id,
|
Id = x.Id,
|
||||||
Name = entity.Name,
|
Name = x.Name,
|
||||||
Description = entity.Description,
|
Description = x.Description,
|
||||||
Type = entity.Type,
|
Type = x.Type,
|
||||||
CreationDate = entity.CreationDate,
|
CreationDate = x.CreationDate,
|
||||||
Mage = MapMageEntityToMageDto(entity.Mage)
|
MageId = x.MageId
|
||||||
};
|
};
|
||||||
SpellDtoCollection.Add(dto);
|
spellDtoCollection.Add(dto);
|
||||||
}
|
}
|
||||||
return SpellDtoCollection;
|
return spellDtoCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellFilter MapSpellDtoFilterToSpellFilterEntity(SpellDtoFilter dto)
|
public SpellDto mapSpellEntityToSpellDto(Spell spell)
|
||||||
{
|
{
|
||||||
SpellFilter entity = new SpellFilter()
|
return new SpellDto()
|
||||||
{
|
{
|
||||||
Id = dto.Id,
|
Id = spell.Id,
|
||||||
Name = dto.Name,
|
Name = spell.Name,
|
||||||
Description = dto.Description,
|
Description = spell.Description,
|
||||||
Type = dto.Type,
|
Type = spell.Type,
|
||||||
CreationDate = dto.CreationDate,
|
CreationDate = spell.CreationDate,
|
||||||
Mage = MapMageDtoFilterToMageFilterEntity(dto.Mage)
|
MageId = spell.MageId
|
||||||
};
|
};
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Spell MapSpellDtoToSpellEntity(SpellDto dto)
|
|
||||||
{
|
|
||||||
Spell entity = new Spell()
|
|
||||||
{
|
|
||||||
Id = dto.Id,
|
|
||||||
Name = dto.Name,
|
|
||||||
Description = dto.Description,
|
|
||||||
Type = dto.Type,
|
|
||||||
CreationDate = dto.CreationDate,
|
|
||||||
Mage = MapMageDtoToMageEntity(dto.Mage)
|
|
||||||
};
|
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,34 +1,8 @@
|
|||||||
using Liber_Incantamentum.Application.DTOs.Filter;
|
using Liber_Incantamentum.Application.Interfaces.Validations;
|
||||||
using Liber_Incantamentum.Application.DTOs.General;
|
|
||||||
using Liber_Incantamentum.Application.Interfaces.Validations;
|
|
||||||
|
|
||||||
namespace Liber_Incantamentum.Application.Services.Validations
|
namespace Liber_Incantamentum.Application.Services.Validations
|
||||||
{
|
{
|
||||||
public class Validator : IValidator
|
public class Validator : IValidator
|
||||||
{
|
{
|
||||||
public void ValidateGuid(Guid id)
|
|
||||||
{
|
|
||||||
if (id == Guid.Empty) throw new ArgumentNullException("The id received is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ValidateMageDto(MageDto dto)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ValidateMageDtoFilter(MageDtoFilter filter)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ValidateSpellDto(SpellDto dto)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ValidateSpellDtoFilter(SpellDtoFilter filter)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,5 +6,6 @@
|
|||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
public required string Rank { get; set; }
|
public required string Rank { get; set; }
|
||||||
public required string Specialisation { get; set; }
|
public required string Specialisation { get; set; }
|
||||||
|
public ICollection<Spell> Spells { get; set; } = new List<Spell>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,12 @@
|
|||||||
{
|
{
|
||||||
public class Spell
|
public class Spell
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; private set; }
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
public required string Description { get; set; }
|
public required string Description { get; set; }
|
||||||
public required string Type { get; set; }
|
public required string Type { get; set; }
|
||||||
public required DateTime CreationDate { get; set; }
|
public required DateTime CreationDate { get; set; }
|
||||||
public required Mage Mage { get; set; }
|
public Guid MageId { get; set; }
|
||||||
|
public Mage Mage { get; set; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace Liber_Incantamentum.Domain.Filter
|
using Liber_Incantamentum.Domain.Entities;
|
||||||
|
|
||||||
|
namespace Liber_Incantamentum.Domain.Filter
|
||||||
{
|
{
|
||||||
public class MageFilter
|
public class MageFilter
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,6 +7,6 @@
|
|||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
public string? Type { get; set; }
|
public string? Type { get; set; }
|
||||||
public DateTime? CreationDate { get; set; }
|
public DateTime? CreationDate { get; set; }
|
||||||
public MageFilter? Mage { get; set; }
|
public Guid? MageId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,10 @@ namespace Liber_Incantamentum.Domain.Repositories
|
|||||||
{
|
{
|
||||||
public interface IMageRepository
|
public interface IMageRepository
|
||||||
{
|
{
|
||||||
Task<ICollection<Mage>?> GetAllMageAsync(MageFilter filter);
|
Task<ICollection<Mage>?> GetAllMageAsync(MageFilter filterEntity);
|
||||||
Task<bool> UpdateMageAsync(MageFilter filter);
|
Task<bool> UpdateMageAsync(Mage entity);
|
||||||
Task<bool> DeleteMageAsync(Guid id);
|
Task<bool> DeleteMageAsync(Guid id);
|
||||||
Task<bool> AddMageAsync(Mage entity);
|
Task<bool> AddMageAsync(Mage entity);
|
||||||
|
Task<Mage> GetMageByIdAsync(Guid id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,10 @@ namespace Liber_Incantamentum.Domain.Repositories
|
|||||||
{
|
{
|
||||||
public interface ISpellRepository
|
public interface ISpellRepository
|
||||||
{
|
{
|
||||||
Task<ICollection<Spell>?> GetAllSpellAsync(SpellFilter filter);
|
Task<ICollection<Spell>?> GetAllSpellAsync(SpellFilter filterEntity);
|
||||||
Task<bool> UpdateSpellAsync(SpellFilter filter);
|
Task<bool> UpdateSpellAsync(Spell entity);
|
||||||
Task<bool> DeleteSpellAsync(Guid id);
|
Task<bool> DeleteSpellAsync(Guid id);
|
||||||
Task<bool> AddSpellAsync(Spell entity);
|
Task<bool> AddSpellAsync(Spell entity);
|
||||||
|
Task<Spell> GetSpellByIdAsync(Guid id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
namespace Liber_Incantamentum.Infrastructure.DependencyInjection
|
||||||
|
{
|
||||||
|
public class DependencyInjection
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,11 +8,22 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Data\**" />
|
<Compile Remove="Data\**" />
|
||||||
<Compile Remove="Repositories\**" />
|
|
||||||
<EmbeddedResource Remove="Data\**" />
|
<EmbeddedResource Remove="Data\**" />
|
||||||
<EmbeddedResource Remove="Repositories\**" />
|
|
||||||
<None Remove="Data\**" />
|
<None Remove="Data\**" />
|
||||||
<None Remove="Repositories\**" />
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migrations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.7" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Liber_Incantamentum.Domain\Liber_Incantamentum.Domain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
using Liber_Incantamentum.Domain.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Liber_Incantamentum.Infrastructure.Persistence
|
||||||
|
{
|
||||||
|
public class AppDbContext : DbContext
|
||||||
|
{
|
||||||
|
public AppDbContext(DbContextOptions options) : base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public DbSet<Mage> Mages { get; set; }
|
||||||
|
public DbSet<Spell> Spells { get; set; }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
using Liber_Incantamentum.Domain.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Liber_Incantamentum.Infrastructure.Persistence.Configurations
|
||||||
|
{
|
||||||
|
public class MageConfiguration : IEntityTypeConfiguration<Mage>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Mage> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable("Mages");
|
||||||
|
|
||||||
|
builder.HasKey(m => m.Id);
|
||||||
|
|
||||||
|
builder.Property(m => m.Id)
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(m => m.Name)
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(200);
|
||||||
|
|
||||||
|
builder.Property(m => m.Rank)
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(200);
|
||||||
|
|
||||||
|
builder.Property(m => m.Specialisation)
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
namespace Liber_Incantamentum.Infrastructure.Persistence.Configurations
|
||||||
|
{
|
||||||
|
internal class SpellConfiguration
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
namespace Liber_Incantamentum.Infrastructure.Repositories
|
||||||
|
{
|
||||||
|
internal class MageRepository
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
namespace Liber_Incantamentum.Infrastructure.Repositories
|
||||||
|
{
|
||||||
|
internal class SpellRepository
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user