diff --git a/Liber_Incantamentum.Application/DTOs/Mage/MageDto.cs b/Liber_Incantamentum.Application/DTOs/Mage/MageDto.cs new file mode 100644 index 0000000..f85d816 --- /dev/null +++ b/Liber_Incantamentum.Application/DTOs/Mage/MageDto.cs @@ -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 Spells { get; set; } = new List(); + } +} diff --git a/Liber_Incantamentum.Application/DTOs/Mage/MageDtoCreate.cs b/Liber_Incantamentum.Application/DTOs/Mage/MageDtoCreate.cs new file mode 100644 index 0000000..9681d3c --- /dev/null +++ b/Liber_Incantamentum.Application/DTOs/Mage/MageDtoCreate.cs @@ -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; } + } +} diff --git a/Liber_Incantamentum.Application/DTOs/Filter/MageDtoFilter.cs b/Liber_Incantamentum.Application/DTOs/Mage/MageDtoFilter.cs similarity index 79% rename from Liber_Incantamentum.Application/DTOs/Filter/MageDtoFilter.cs rename to Liber_Incantamentum.Application/DTOs/Mage/MageDtoFilter.cs index e19255d..46eccf6 100644 --- a/Liber_Incantamentum.Application/DTOs/Filter/MageDtoFilter.cs +++ b/Liber_Incantamentum.Application/DTOs/Mage/MageDtoFilter.cs @@ -1,4 +1,4 @@ -namespace Liber_Incantamentum.Application.DTOs.Filter +namespace Liber_Incantamentum.Application.DTOs.Mage { public class MageDtoFilter { diff --git a/Liber_Incantamentum.Application/DTOs/General/MageDto.cs b/Liber_Incantamentum.Application/DTOs/Mage/MageDtoUpdate.cs similarity index 71% rename from Liber_Incantamentum.Application/DTOs/General/MageDto.cs rename to Liber_Incantamentum.Application/DTOs/Mage/MageDtoUpdate.cs index 389807b..a6f6a4c 100644 --- a/Liber_Incantamentum.Application/DTOs/General/MageDto.cs +++ b/Liber_Incantamentum.Application/DTOs/Mage/MageDtoUpdate.cs @@ -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 required string Name { get; set; } diff --git a/Liber_Incantamentum.Application/DTOs/General/SpellDto.cs b/Liber_Incantamentum.Application/DTOs/Spell/SpellDto.cs similarity index 73% rename from Liber_Incantamentum.Application/DTOs/General/SpellDto.cs rename to Liber_Incantamentum.Application/DTOs/Spell/SpellDto.cs index 834f7cf..f078fc6 100644 --- a/Liber_Incantamentum.Application/DTOs/General/SpellDto.cs +++ b/Liber_Incantamentum.Application/DTOs/Spell/SpellDto.cs @@ -1,4 +1,4 @@ -namespace Liber_Incantamentum.Application.DTOs.General +namespace Liber_Incantamentum.Application.DTOs.Spell { public class SpellDto { @@ -7,6 +7,6 @@ public required string Description { get; set; } public required string Type { get; set; } public required DateTime CreationDate { get; set; } - public required MageDto Mage { get; set; } + public Guid MageId { get; set; } } } diff --git a/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoCreate.cs b/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoCreate.cs new file mode 100644 index 0000000..e70aeac --- /dev/null +++ b/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoCreate.cs @@ -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; } + } +} diff --git a/Liber_Incantamentum.Application/DTOs/Filter/SpellDtoFilter.cs b/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoFilter.cs similarity index 61% rename from Liber_Incantamentum.Application/DTOs/Filter/SpellDtoFilter.cs rename to Liber_Incantamentum.Application/DTOs/Spell/SpellDtoFilter.cs index e5ef457..0112012 100644 --- a/Liber_Incantamentum.Application/DTOs/Filter/SpellDtoFilter.cs +++ b/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoFilter.cs @@ -1,12 +1,12 @@ -namespace Liber_Incantamentum.Application.DTOs.Filter +namespace Liber_Incantamentum.Application.DTOs.Spell { public class SpellDtoFilter { - public Guid? Id { get; set; } + public Guid Id { get; set; } public string? Name { get; set; } public string? Description { get; set; } public string? Type { get; set; } public DateTime? CreationDate { get; set; } - public MageDtoFilter? Mage { get; set; } + public Guid? MageId { get; set; } } } diff --git a/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoUpdate.cs b/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoUpdate.cs new file mode 100644 index 0000000..6900f09 --- /dev/null +++ b/Liber_Incantamentum.Application/DTOs/Spell/SpellDtoUpdate.cs @@ -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; } + } +} diff --git a/Liber_Incantamentum.Application/Interfaces/Generals/IMageService.cs b/Liber_Incantamentum.Application/Interfaces/Generals/IMageService.cs index b43ca92..da7f0ef 100644 --- a/Liber_Incantamentum.Application/Interfaces/Generals/IMageService.cs +++ b/Liber_Incantamentum.Application/Interfaces/Generals/IMageService.cs @@ -1,13 +1,13 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; +using Liber_Incantamentum.Application.DTOs.Mage; namespace Liber_Incantamentum.Application.Interfaces.Generals { public interface IMageService { Task?> GetAllMageAsync(MageDtoFilter filter); - Task UpdateMageAsync(MageDtoFilter dto); + Task UpdateMageAsync(MageDtoUpdate dto); Task DeleteMageAsync(Guid id); - Task AddMageAsync(MageDto dto); + Task AddMageAsync(MageDtoCreate dto); + Task GetMageByIdAsync(Guid id); } } diff --git a/Liber_Incantamentum.Application/Interfaces/Generals/ISpellService.cs b/Liber_Incantamentum.Application/Interfaces/Generals/ISpellService.cs index 2333f22..ed44c64 100644 --- a/Liber_Incantamentum.Application/Interfaces/Generals/ISpellService.cs +++ b/Liber_Incantamentum.Application/Interfaces/Generals/ISpellService.cs @@ -1,13 +1,14 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; +using Liber_Incantamentum.Application.DTOs.Mage; +using Liber_Incantamentum.Application.DTOs.Spell; namespace Liber_Incantamentum.Application.Interfaces.Generals { public interface ISpellService { Task?> GetAllSpellAsync(SpellDtoFilter filter); - Task UpdateSpellAsync(SpellDtoFilter dto); + Task UpdateSpellAsync(SpellDtoUpdate dto); Task DeleteSpellAsync(Guid id); - Task AddSpellAsync(SpellDto dto); + Task AddSpellAsync(SpellDtoCreate dto); + Task GetSpellByIdAsync(Guid id); } -} +} \ No newline at end of file diff --git a/Liber_Incantamentum.Application/Interfaces/Mappings/IMapper.cs b/Liber_Incantamentum.Application/Interfaces/Mappings/IMapper.cs index e37f5ac..64d5849 100644 --- a/Liber_Incantamentum.Application/Interfaces/Mappings/IMapper.cs +++ b/Liber_Incantamentum.Application/Interfaces/Mappings/IMapper.cs @@ -1,5 +1,5 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; +using Liber_Incantamentum.Application.DTOs.Mage; +using Liber_Incantamentum.Application.DTOs.Spell; using Liber_Incantamentum.Domain.Entities; using Liber_Incantamentum.Domain.Filter; @@ -7,10 +7,15 @@ namespace Liber_Incantamentum.Application.Interfaces.Mappings { public interface IMapper { - MageFilter MapMageDtoFilterToMageFilterEntity(MageDtoFilter filter); - Mage MapMageDtoToMageEntity(MageDto dto); - ICollection? MapMageEntityCollectionToMageDtoCollection(ICollection? task); - SpellFilter MapSpellDtoFilterToSpellFilterEntity(SpellDtoFilter dto); - Spell MapSpellDtoToSpellEntity(SpellDto dto); + Mage MapMageDtoCreateToMageEntity(MageDtoCreate value); + MageFilter MapMageDtoFilterToMageFilter(MageDtoFilter value); + Mage MapMageDtoUpdateToMageEntity(MageDtoUpdate value); + ICollection? MapMageEntityCollectionToMageDtoCollection(ICollection? value); + MageDto mapMageEntityToMageDto(Mage mage); + Spell MapSpellDtoCreateToSpellEntity(SpellDtoCreate value); + SpellFilter MapSpellDtoFilterToSpellFilter(SpellDtoFilter value); + Spell MapSpellDtoUpdateToSpellEntity(SpellDtoUpdate value); + ICollection? MapSpellEntityCollectionToSpellDtoCollection(ICollection? value); + SpellDto mapSpellEntityToSpellDto(Spell spell); } } diff --git a/Liber_Incantamentum.Application/Interfaces/Validations/IValidator.cs b/Liber_Incantamentum.Application/Interfaces/Validations/IValidator.cs index fdb4ad7..8b968f1 100644 --- a/Liber_Incantamentum.Application/Interfaces/Validations/IValidator.cs +++ b/Liber_Incantamentum.Application/Interfaces/Validations/IValidator.cs @@ -1,14 +1,18 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; +using Liber_Incantamentum.Application.DTOs.Mage; +using Liber_Incantamentum.Application.DTOs.Spell; namespace Liber_Incantamentum.Application.Interfaces.Validations { public interface IValidator { - void ValidateGuid(Guid id); - void ValidateMageDto(MageDto dto); - void ValidateMageDtoFilter(MageDtoFilter filter); - void ValidateSpellDto(SpellDto dto); - void ValidateSpellDtoFilter(SpellDtoFilter filter); + void ValidateGuid(Guid value); + void ValidateMageDto(MageDto value); + void ValidateMageDtoCreate(MageDtoCreate value); + void ValidateMageDtoUpdate(MageDtoUpdate value); + void ValidateMageDtoFilter(MageDtoFilter value); + void ValidateSpellDto(SpellDto value); + void ValidateSpellDtoCreate(SpellDtoCreate value); + void ValidateSpellDtoUpdate(SpellDtoUpdate value); + void ValidateSpellDtoFilter(SpellDtoFilter value); } } diff --git a/Liber_Incantamentum.Application/Services/Generals/MageService.cs b/Liber_Incantamentum.Application/Services/Generals/MageService.cs index 7933a2f..2c8459c 100644 --- a/Liber_Incantamentum.Application/Services/Generals/MageService.cs +++ b/Liber_Incantamentum.Application/Services/Generals/MageService.cs @@ -1,5 +1,4 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; +using Liber_Incantamentum.Application.DTOs.Mage; using Liber_Incantamentum.Application.Interfaces.Generals; using Liber_Incantamentum.Application.Interfaces.Mappings; using Liber_Incantamentum.Application.Interfaces.Validations; @@ -18,10 +17,11 @@ namespace Liber_Incantamentum.Application.Services.Generals _mageRepository = mageRepository; _validator = validator; } - public async Task AddMageAsync(MageDto dto) + + public async Task AddMageAsync(MageDtoCreate dto) { - _validator.ValidateMageDto(dto); - return await _mageRepository.AddMageAsync(_mapper.MapMageDtoToMageEntity(dto)); + _validator.ValidateMageDtoCreate(dto); + return await _mageRepository.AddMageAsync(_mapper.MapMageDtoCreateToMageEntity(dto)); } public async Task DeleteMageAsync(Guid id) @@ -33,14 +33,19 @@ namespace Liber_Incantamentum.Application.Services.Generals public async Task?> GetAllMageAsync(MageDtoFilter 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 UpdateMageAsync(MageDtoFilter dto) + public async Task GetMageByIdAsync(Guid id) { - _validator.ValidateMageDtoFilter(dto); - await _mageRepository.UpdateMageAsync(_mapper.MapMageDtoFilterToMageFilterEntity(dto)); - return false; + _validator.ValidateGuid(id); + return _mapper.mapMageEntityToMageDto(await _mageRepository.GetMageByIdAsync(id)); + } + + public Task UpdateMageAsync(MageDtoUpdate dto) + { + _validator.ValidateMageDtoUpdate(dto); + return _mageRepository.UpdateMageAsync(_mapper.MapMageDtoUpdateToMageEntity(dto)); } } } diff --git a/Liber_Incantamentum.Application/Services/Generals/SpellService.cs b/Liber_Incantamentum.Application/Services/Generals/SpellService.cs index 4ba4063..2bcc43e 100644 --- a/Liber_Incantamentum.Application/Services/Generals/SpellService.cs +++ b/Liber_Incantamentum.Application/Services/Generals/SpellService.cs @@ -1,5 +1,5 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; +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; @@ -18,40 +18,34 @@ namespace Liber_Incantamentum.Application.Services.Generals _validator = validator; _spellRepository = spellRepository; } - public async Task AddSpellAsync(SpellDto dto) + public async Task AddSpellAsync(SpellDtoCreate dto) { - if (_validator.ValidateSpellDto(dto)) - { - await _spellRepository.AddSpellAsync(_mapper.MapSpellDtoToSpellEntity(dto)); - } - return false; + _validator.ValidateSpellDtoCreate(dto); + return await _spellRepository.AddSpellAsync(_mapper.MapSpellDtoCreateToSpellEntity(dto)); } public async Task DeleteSpellAsync(Guid id) { - if (_validator.ValidateGuid(id)) - { - await _spellRepository.DeleteSpellAsync(id); - } - return false; + _validator.ValidateGuid(id); + return await _spellRepository.DeleteSpellAsync(id); } public async Task?> GetAllSpellAsync(SpellDtoFilter filter) { - if (_validator.ValidateSpellDtoFilter(filter)) - { - await _spellRepository.GetAllSpellAsync(_mapper.MapSpellDtoFilterToSpellFilterEntity(filter)); - } - return null; + _validator.ValidateSpellDtoFilter(filter); + return _mapper.MapSpellEntityCollectionToSpellDtoCollection(await _spellRepository.GetAllSpellAsync(_mapper.MapSpellDtoFilterToSpellFilter(filter))); } - public async Task UpdateSpellAsync(SpellDtoFilter filter) + public async Task GetSpellByIdAsync(Guid id) { - if (_validator.ValidateSpellDtoFilter(filter)) - { - await _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoFilterToSpellFilterEntity(filter)); - } - return false; + _validator.ValidateGuid(id); + return _mapper.mapSpellEntityToSpellDto(await _spellRepository.GetSpellByIdAsync(id)); + } + + public Task UpdateSpellAsync(SpellDtoUpdate dto) + { + _validator.ValidateSpellDtoUpdate(dto); + return _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoUpdateToSpellEntity(dto)); } } } diff --git a/Liber_Incantamentum.Application/Services/Mappings/Mapper.cs b/Liber_Incantamentum.Application/Services/Mappings/Mapper.cs index 2b32915..3db232e 100644 --- a/Liber_Incantamentum.Application/Services/Mappings/Mapper.cs +++ b/Liber_Incantamentum.Application/Services/Mappings/Mapper.cs @@ -1,51 +1,48 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; +using Liber_Incantamentum.Application.DTOs.Mage; +using Liber_Incantamentum.Application.DTOs.Spell; using Liber_Incantamentum.Application.Interfaces.Mappings; using Liber_Incantamentum.Domain.Entities; using Liber_Incantamentum.Domain.Filter; -using System.Collections; namespace Liber_Incantamentum.Application.Services.Mappings { 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 = filter.Name, - Rank = filter.Rank, - Specialisation = filter.Specialisation + Name = value.Name, + Rank = value.Rank, + Specialisation = value.Specialisation }; - return entity; } - public Mage MapMageDtoToMageEntity(MageDto dto) + public MageFilter MapMageDtoFilterToMageFilter(MageDtoFilter value) { - Mage entity = new Mage() + return new MageFilter() { - Name = dto.Name, - Rank = dto.Rank, - Specialisation = dto.Specialisation + Id = value.Id, + Name = value.Name, + 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? MapMageEntityCollectionToMageDtoCollection(ICollection collection) + public Mage MapMageDtoUpdateToMageEntity(MageDtoUpdate value) { - ICollection MageDtoCollection = new List(); - foreach(var entity in collection) + return new Mage() + { + Name = value.Name, + Rank = value.Rank, + Specialisation = value.Specialisation + }; + } + + public ICollection? MapMageEntityCollectionToMageDtoCollection(ICollection? value) + { + var mageDtoCollection = new List(); + foreach (var entity in value) { MageDto dto = new MageDto() { @@ -54,55 +51,91 @@ namespace Liber_Incantamentum.Application.Services.Mappings Rank = entity.Rank, Specialisation = entity.Specialisation }; - MageDtoCollection.Add(dto); + + mageDtoCollection.Add(dto); } - return MageDtoCollection; + + return mageDtoCollection; } - public ICollection? MapSpellEntityCollectionToSpellDtoCollection(ICollection collection) + + public MageDto mapMageEntityToMageDto(Mage mage) { - ICollection SpellDtoCollection = new List(); - foreach (var entity in collection) + return new MageDto() { - 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? MapSpellEntityCollectionToSpellDtoCollection(ICollection? value) + { + var spellDtoCollection = new List(); + foreach (var x in value) + { + var dto = new SpellDto() { - Id = entity.Id, - Name = entity.Name, - Description = entity.Description, - Type = entity.Type, - CreationDate = entity.CreationDate, - Mage = MapMageEntityToMageDto(entity.Mage) + Id = x.Id, + Name = x.Name, + Description = x.Description, + Type = x.Type, + CreationDate = x.CreationDate, + 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, - Name = dto.Name, - Description = dto.Description, - Type = dto.Type, - CreationDate = dto.CreationDate, - Mage = MapMageDtoFilterToMageFilterEntity(dto.Mage) + Id = spell.Id, + Name = spell.Name, + Description = spell.Description, + Type = spell.Type, + CreationDate = spell.CreationDate, + 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; } } } diff --git a/Liber_Incantamentum.Application/Services/Validations/Validator.cs b/Liber_Incantamentum.Application/Services/Validations/Validator.cs index 4d9fbd5..fb03a5b 100644 --- a/Liber_Incantamentum.Application/Services/Validations/Validator.cs +++ b/Liber_Incantamentum.Application/Services/Validations/Validator.cs @@ -1,34 +1,8 @@ -using Liber_Incantamentum.Application.DTOs.Filter; -using Liber_Incantamentum.Application.DTOs.General; -using Liber_Incantamentum.Application.Interfaces.Validations; +using Liber_Incantamentum.Application.Interfaces.Validations; namespace Liber_Incantamentum.Application.Services.Validations { 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(); - } } } diff --git a/Liber_Incantamentum.Domain/Entities/Mage.cs b/Liber_Incantamentum.Domain/Entities/Mage.cs index c48859d..04c94a6 100644 --- a/Liber_Incantamentum.Domain/Entities/Mage.cs +++ b/Liber_Incantamentum.Domain/Entities/Mage.cs @@ -6,5 +6,6 @@ public required string Name { get; set; } public required string Rank { get; set; } public required string Specialisation { get; set; } + public ICollection Spells { get; set; } = new List(); } } diff --git a/Liber_Incantamentum.Domain/Entities/Spell.cs b/Liber_Incantamentum.Domain/Entities/Spell.cs index cbb443b..e5be4e3 100644 --- a/Liber_Incantamentum.Domain/Entities/Spell.cs +++ b/Liber_Incantamentum.Domain/Entities/Spell.cs @@ -2,11 +2,12 @@ { public class Spell { - public Guid Id { get; set; } + public Guid Id { get; private 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 required Mage Mage { get; set; } + public Guid MageId { get; set; } + public Mage Mage { get; set; } = null!; } } diff --git a/Liber_Incantamentum.Domain/Filter/MageFilter.cs b/Liber_Incantamentum.Domain/Filter/MageFilter.cs index 39354be..3481ba8 100644 --- a/Liber_Incantamentum.Domain/Filter/MageFilter.cs +++ b/Liber_Incantamentum.Domain/Filter/MageFilter.cs @@ -1,4 +1,6 @@ -namespace Liber_Incantamentum.Domain.Filter +using Liber_Incantamentum.Domain.Entities; + +namespace Liber_Incantamentum.Domain.Filter { public class MageFilter { diff --git a/Liber_Incantamentum.Domain/Filter/SpellFilter.cs b/Liber_Incantamentum.Domain/Filter/SpellFilter.cs index d1c19c8..4092d8f 100644 --- a/Liber_Incantamentum.Domain/Filter/SpellFilter.cs +++ b/Liber_Incantamentum.Domain/Filter/SpellFilter.cs @@ -7,6 +7,6 @@ public string? Description { get; set; } public string? Type { get; set; } public DateTime? CreationDate { get; set; } - public MageFilter? Mage { get; set; } + public Guid? MageId { get; set; } } } diff --git a/Liber_Incantamentum.Domain/Repositories/IMageRepository.cs b/Liber_Incantamentum.Domain/Repositories/IMageRepository.cs index 3a32d96..9d99760 100644 --- a/Liber_Incantamentum.Domain/Repositories/IMageRepository.cs +++ b/Liber_Incantamentum.Domain/Repositories/IMageRepository.cs @@ -5,9 +5,10 @@ namespace Liber_Incantamentum.Domain.Repositories { public interface IMageRepository { - Task?> GetAllMageAsync(MageFilter filter); - Task UpdateMageAsync(MageFilter filter); + Task?> GetAllMageAsync(MageFilter filterEntity); + Task UpdateMageAsync(Mage entity); Task DeleteMageAsync(Guid id); Task AddMageAsync(Mage entity); + Task GetMageByIdAsync(Guid id); } } diff --git a/Liber_Incantamentum.Domain/Repositories/ISpellRepository.cs b/Liber_Incantamentum.Domain/Repositories/ISpellRepository.cs index d63a194..22d758d 100644 --- a/Liber_Incantamentum.Domain/Repositories/ISpellRepository.cs +++ b/Liber_Incantamentum.Domain/Repositories/ISpellRepository.cs @@ -5,9 +5,10 @@ namespace Liber_Incantamentum.Domain.Repositories { public interface ISpellRepository { - Task?> GetAllSpellAsync(SpellFilter filter); - Task UpdateSpellAsync(SpellFilter filter); + Task?> GetAllSpellAsync(SpellFilter filterEntity); + Task UpdateSpellAsync(Spell entity); Task DeleteSpellAsync(Guid id); Task AddSpellAsync(Spell entity); + Task GetSpellByIdAsync(Guid id); } } diff --git a/Liber_Incantamentum.Infrastructure/DependencyInjection/DependencyInjection.cs b/Liber_Incantamentum.Infrastructure/DependencyInjection/DependencyInjection.cs new file mode 100644 index 0000000..8cc6275 --- /dev/null +++ b/Liber_Incantamentum.Infrastructure/DependencyInjection/DependencyInjection.cs @@ -0,0 +1,6 @@ +namespace Liber_Incantamentum.Infrastructure.DependencyInjection +{ + public class DependencyInjection + { + } +} diff --git a/Liber_Incantamentum.Infrastructure/Liber_Incantamentum.Infrastructure.csproj b/Liber_Incantamentum.Infrastructure/Liber_Incantamentum.Infrastructure.csproj index 0e62045..0ef0e05 100644 --- a/Liber_Incantamentum.Infrastructure/Liber_Incantamentum.Infrastructure.csproj +++ b/Liber_Incantamentum.Infrastructure/Liber_Incantamentum.Infrastructure.csproj @@ -8,11 +8,22 @@ - - - + + + + + + + + + + + + + + diff --git a/Liber_Incantamentum.Infrastructure/Persistence/AppDbContext.cs b/Liber_Incantamentum.Infrastructure/Persistence/AppDbContext.cs new file mode 100644 index 0000000..ef65ced --- /dev/null +++ b/Liber_Incantamentum.Infrastructure/Persistence/AppDbContext.cs @@ -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 Mages { get; set; } + public DbSet Spells { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly); + base.OnModelCreating(modelBuilder); + } + } + +} diff --git a/Liber_Incantamentum.Infrastructure/Persistence/Configurations/MageConfiguration.cs b/Liber_Incantamentum.Infrastructure/Persistence/Configurations/MageConfiguration.cs new file mode 100644 index 0000000..80ecd38 --- /dev/null +++ b/Liber_Incantamentum.Infrastructure/Persistence/Configurations/MageConfiguration.cs @@ -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 + { + public void Configure(EntityTypeBuilder 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); + } + } +} diff --git a/Liber_Incantamentum.Infrastructure/Persistence/Configurations/SpellConfiguration.cs b/Liber_Incantamentum.Infrastructure/Persistence/Configurations/SpellConfiguration.cs new file mode 100644 index 0000000..cfdb616 --- /dev/null +++ b/Liber_Incantamentum.Infrastructure/Persistence/Configurations/SpellConfiguration.cs @@ -0,0 +1,6 @@ +namespace Liber_Incantamentum.Infrastructure.Persistence.Configurations +{ + internal class SpellConfiguration + { + } +} diff --git a/Liber_Incantamentum.Infrastructure/Repositories/MageRepository.cs b/Liber_Incantamentum.Infrastructure/Repositories/MageRepository.cs new file mode 100644 index 0000000..3d711ed --- /dev/null +++ b/Liber_Incantamentum.Infrastructure/Repositories/MageRepository.cs @@ -0,0 +1,6 @@ +namespace Liber_Incantamentum.Infrastructure.Repositories +{ + internal class MageRepository + { + } +} diff --git a/Liber_Incantamentum.Infrastructure/Repositories/SpellRepository.cs b/Liber_Incantamentum.Infrastructure/Repositories/SpellRepository.cs new file mode 100644 index 0000000..50c646a --- /dev/null +++ b/Liber_Incantamentum.Infrastructure/Repositories/SpellRepository.cs @@ -0,0 +1,6 @@ +namespace Liber_Incantamentum.Infrastructure.Repositories +{ + internal class SpellRepository + { + } +}