This commit is contained in:
blyssco 2025-08-02 18:56:44 +02:00
parent 5cd762fc3d
commit 39b8312807
29 changed files with 324 additions and 169 deletions

View 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>();
}
}

View File

@ -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; }
}
}

View File

@ -1,4 +1,4 @@
namespace Liber_Incantamentum.Application.DTOs.Filter
namespace Liber_Incantamentum.Application.DTOs.Mage
{
public class MageDtoFilter
{

View File

@ -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; }

View File

@ -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; }
}
}

View 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; }
}
}

View File

@ -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; }
}
}

View 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; }
}
}

View File

@ -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<ICollection<MageDto>?> GetAllMageAsync(MageDtoFilter filter);
Task<bool> UpdateMageAsync(MageDtoFilter dto);
Task<bool> UpdateMageAsync(MageDtoUpdate dto);
Task<bool> DeleteMageAsync(Guid id);
Task<bool> AddMageAsync(MageDto dto);
Task<bool> AddMageAsync(MageDtoCreate dto);
Task<MageDto> GetMageByIdAsync(Guid id);
}
}

View File

@ -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<ICollection<SpellDto>?> GetAllSpellAsync(SpellDtoFilter filter);
Task<bool> UpdateSpellAsync(SpellDtoFilter dto);
Task<bool> UpdateSpellAsync(SpellDtoUpdate dto);
Task<bool> DeleteSpellAsync(Guid id);
Task<bool> AddSpellAsync(SpellDto dto);
Task<bool> AddSpellAsync(SpellDtoCreate dto);
Task<SpellDto> GetSpellByIdAsync(Guid id);
}
}
}

View File

@ -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<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage>? task);
SpellFilter MapSpellDtoFilterToSpellFilterEntity(SpellDtoFilter dto);
Spell MapSpellDtoToSpellEntity(SpellDto dto);
Mage MapMageDtoCreateToMageEntity(MageDtoCreate value);
MageFilter MapMageDtoFilterToMageFilter(MageDtoFilter value);
Mage MapMageDtoUpdateToMageEntity(MageDtoUpdate value);
ICollection<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage>? value);
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);
}
}

View File

@ -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);
}
}

View File

@ -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<bool> AddMageAsync(MageDto dto)
public async Task<bool> 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<bool> DeleteMageAsync(Guid id)
@ -33,14 +33,19 @@ namespace Liber_Incantamentum.Application.Services.Generals
public async Task<ICollection<MageDto>?> 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<bool> UpdateMageAsync(MageDtoFilter dto)
public async Task<MageDto> 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<bool> UpdateMageAsync(MageDtoUpdate dto)
{
_validator.ValidateMageDtoUpdate(dto);
return _mageRepository.UpdateMageAsync(_mapper.MapMageDtoUpdateToMageEntity(dto));
}
}
}

View File

@ -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<bool> AddSpellAsync(SpellDto dto)
public async Task<bool> 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<bool> DeleteSpellAsync(Guid id)
{
if (_validator.ValidateGuid(id))
{
await _spellRepository.DeleteSpellAsync(id);
}
return false;
_validator.ValidateGuid(id);
return await _spellRepository.DeleteSpellAsync(id);
}
public async Task<ICollection<SpellDto>?> 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<bool> UpdateSpellAsync(SpellDtoFilter filter)
public async Task<SpellDto> 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<bool> UpdateSpellAsync(SpellDtoUpdate dto)
{
_validator.ValidateSpellDtoUpdate(dto);
return _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoUpdateToSpellEntity(dto));
}
}
}

View File

@ -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<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage> collection)
public Mage MapMageDtoUpdateToMageEntity(MageDtoUpdate value)
{
ICollection<MageDto> MageDtoCollection = new List<MageDto>();
foreach(var entity in collection)
return new Mage()
{
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()
{
@ -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<SpellDto>? MapSpellEntityCollectionToSpellDtoCollection(ICollection<Spell> collection)
public MageDto mapMageEntityToMageDto(Mage mage)
{
ICollection<SpellDto> SpellDtoCollection = new List<SpellDto>();
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<SpellDto>? MapSpellEntityCollectionToSpellDtoCollection(ICollection<Spell>? value)
{
var spellDtoCollection = new List<SpellDto>();
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;
}
}
}

View File

@ -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();
}
}
}

View File

@ -6,5 +6,6 @@
public required string Name { get; set; }
public required string Rank { get; set; }
public required string Specialisation { get; set; }
public ICollection<Spell> Spells { get; set; } = new List<Spell>();
}
}

View File

@ -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!;
}
}

View File

@ -1,4 +1,6 @@
namespace Liber_Incantamentum.Domain.Filter
using Liber_Incantamentum.Domain.Entities;
namespace Liber_Incantamentum.Domain.Filter
{
public class MageFilter
{

View File

@ -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; }
}
}

View File

@ -5,9 +5,10 @@ namespace Liber_Incantamentum.Domain.Repositories
{
public interface IMageRepository
{
Task<ICollection<Mage>?> GetAllMageAsync(MageFilter filter);
Task<bool> UpdateMageAsync(MageFilter filter);
Task<ICollection<Mage>?> GetAllMageAsync(MageFilter filterEntity);
Task<bool> UpdateMageAsync(Mage entity);
Task<bool> DeleteMageAsync(Guid id);
Task<bool> AddMageAsync(Mage entity);
Task<Mage> GetMageByIdAsync(Guid id);
}
}

View File

@ -5,9 +5,10 @@ namespace Liber_Incantamentum.Domain.Repositories
{
public interface ISpellRepository
{
Task<ICollection<Spell>?> GetAllSpellAsync(SpellFilter filter);
Task<bool> UpdateSpellAsync(SpellFilter filter);
Task<ICollection<Spell>?> GetAllSpellAsync(SpellFilter filterEntity);
Task<bool> UpdateSpellAsync(Spell entity);
Task<bool> DeleteSpellAsync(Guid id);
Task<bool> AddSpellAsync(Spell entity);
Task<Spell> GetSpellByIdAsync(Guid id);
}
}

View File

@ -0,0 +1,6 @@
namespace Liber_Incantamentum.Infrastructure.DependencyInjection
{
public class DependencyInjection
{
}
}

View File

@ -8,11 +8,22 @@
<ItemGroup>
<Compile Remove="Data\**" />
<Compile Remove="Repositories\**" />
<EmbeddedResource Remove="Data\**" />
<EmbeddedResource Remove="Repositories\**" />
<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>
</Project>

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,6 @@
namespace Liber_Incantamentum.Infrastructure.Persistence.Configurations
{
internal class SpellConfiguration
{
}
}

View File

@ -0,0 +1,6 @@
namespace Liber_Incantamentum.Infrastructure.Repositories
{
internal class MageRepository
{
}
}

View File

@ -0,0 +1,6 @@
namespace Liber_Incantamentum.Infrastructure.Repositories
{
internal class SpellRepository
{
}
}