From 4688868f04e6d37a9b98490c2025f3e1a2c3a07e Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 21 Apr 2024 22:58:19 +0200 Subject: [PATCH] Fix season and episode slugs on update --- .../Repositories/EpisodeRepository.cs | 11 +++-------- .../Repositories/SeasonRepository.cs | 19 +++++++------------ 2 files changed, 10 insertions(+), 20 deletions(-) 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); } }