diff --git a/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs index d3162666..62e587ba 100644 --- a/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs +++ b/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs @@ -71,14 +71,6 @@ public class EpisodeRepository( .ToListAsync(); } - /// - public override async Task Create(Episode obj) - { - // Set it for the OnResourceCreated event and the return value. - obj.ShowSlug = obj.Show?.Slug ?? (await shows.Get(obj.ShowId)).Slug; - return await base.Create(obj); - } - /// protected override async Task Validate(Episode resource) { @@ -86,6 +78,9 @@ public class EpisodeRepository( resource.Show = null; if (resource.ShowId == Guid.Empty) throw new ValidationException("Missing show id"); + // This is storred in db so it needs to be set before every create/edit (and before events) + resource.ShowSlug = (await shows.Get(resource.ShowId)).Slug; + resource.Season = null; if (resource.SeasonId == null && resource.SeasonNumber != null) { diff --git a/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs index 590d0b10..aa314440 100644 --- a/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs +++ b/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs @@ -31,8 +31,11 @@ using Microsoft.Extensions.DependencyInjection; namespace Kyoo.Core.Controllers; -public class SeasonRepository(DatabaseContext database, IThumbnailsManager thumbnails) - : GenericRepository(database) +public class SeasonRepository( + DatabaseContext database, + IRepository shows, + IThumbnailsManager thumbnails +) : GenericRepository(database) { static SeasonRepository() { @@ -66,16 +69,6 @@ public class SeasonRepository(DatabaseContext database, IThumbnailsManager thumb .ToListAsync(); } - /// - public override async Task Create(Season obj) - { - // Set it for the OnResourceCreated event and the return value. - obj.ShowSlug = - (await Database.Shows.FirstOrDefaultAsync(x => x.Id == obj.ShowId))?.Slug - ?? throw new ItemNotFoundException($"No show found with ID {obj.ShowId}"); - return await base.Create(obj); - } - /// protected override async Task Validate(Season resource) { @@ -83,6 +76,8 @@ public class SeasonRepository(DatabaseContext database, IThumbnailsManager thumb resource.Show = null; if (resource.ShowId == Guid.Empty) throw new ValidationException("Missing show id"); + // This is storred in db so it needs to be set before every create/edit (and before events) + resource.ShowSlug = (await shows.Get(resource.ShowId)).Slug; await thumbnails.DownloadImages(resource); } }