Fix season and episode slugs on update

This commit is contained in:
Zoe Roux 2024-04-21 22:58:19 +02:00
parent 5a6da7441f
commit 4688868f04
No known key found for this signature in database
2 changed files with 10 additions and 20 deletions

View File

@ -71,14 +71,6 @@ public class EpisodeRepository(
.ToListAsync();
}
/// <inheritdoc />
public override async Task<Episode> 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);
}
/// <inheritdoc />
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)
{

View File

@ -31,8 +31,11 @@ using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Core.Controllers;
public class SeasonRepository(DatabaseContext database, IThumbnailsManager thumbnails)
: GenericRepository<Season>(database)
public class SeasonRepository(
DatabaseContext database,
IRepository<Show> shows,
IThumbnailsManager thumbnails
) : GenericRepository<Season>(database)
{
static SeasonRepository()
{
@ -66,16 +69,6 @@ public class SeasonRepository(DatabaseContext database, IThumbnailsManager thumb
.ToListAsync();
}
/// <inheritdoc/>
public override async Task<Season> 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);
}
/// <inheritdoc/>
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);
}
}