fix services

This commit is contained in:
2025-05-02 22:27:17 +02:00
parent 9fdd25172c
commit f32ada4fce
2 changed files with 9 additions and 20 deletions

View File

@@ -23,9 +23,9 @@ public class GameProfile : Profile
.ForMember(d => d.Properties, o => o.MapFrom(s => s.GameProperties.Select(p => p.Property)))
.ForMember(d => d.Tags, o => o.MapFrom(s => s.GameTags.Select(t => t.Tag)))
.ForMember(d => d.Publisher, o => o.MapFrom(s => s.Publisher))
.ForMember(d => d.Publisher!.Id, o => o.MapFrom(s => s.PublisherId))
.ForPath(d => d.Publisher!.Id, o => o.MapFrom(s => s.PublisherId))
.ForMember(d => d.Developer, o => o.MapFrom(s => s.Developer))
.ForMember(d => d.Developer!.Id, o => o.MapFrom(s => s.DeveloperId))
.ForPath(d => d.Developer!.Id, o => o.MapFrom(s => s.DeveloperId))
.ReverseMap();
CreateMap<Game, GameDto>()

View File

@@ -14,9 +14,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
{
var gameToCreate = mapper.Map<Game>(gameDto);
await HandlePublisherCreation(gameDto.Publisher);
await HandleDeveloperCreation(gameDto.Developer);
HandleDeveloperPublisherCreation(gameToCreate);
await context.Games.AddAsync(gameToCreate);
await context.SaveChangesAsync();
@@ -38,9 +36,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
var gameToUpdate = mapper.Map<Game>(gameDto);
await HandlePublisherCreation(gameDto.Publisher);
await HandleDeveloperCreation(gameDto.Developer);
HandleDeveloperPublisherCreation(gameToUpdate);
await HandlePlatformsCreation(gameDto.Platforms, gameToUpdate.Id);
await HandlePropertiesCreation(gameDto.Properties, gameToUpdate.Id);
await HandleTagsCreation(gameDto.Tags, gameToUpdate.Id);
@@ -109,23 +105,16 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
}
}
private async Task HandlePublisherCreation(PublisherDto? categoriesToCreate)
private void HandleDeveloperPublisherCreation(Game? game)
{
if (categoriesToCreate != null)
if (game?.Publisher != null)
{
var pub = mapper.Map<Publisher>(categoriesToCreate);
context.Publishers.Attach(pub);
await context.Publishers.AddAsync(pub);
context.Publishers.Attach(game.Publisher);
}
}
private async Task HandleDeveloperCreation(DeveloperDto? categoriesToCreate)
{
if (categoriesToCreate != null)
if (game?.Developer != null)
{
var dev = mapper.Map<Developer>(categoriesToCreate);
context.Developers.Attach(dev);
await context.Developers.AddAsync(dev);
context.Developers.Attach(game.Developer);
}
}
}