Update scheduling parameters and refactor channel endpoints: extend HorizonDays to 7 and RetentionDays to 90 in appsettings.json. Consolidate channel-related endpoint logic by removing obsolete files and enhancing the ShowEndpoints with audience and genre management capabilities. Improve error handling and streamline command handlers for channel operations.
This commit is contained in:
@@ -2,6 +2,7 @@ using LiteCqrs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Common.Models;
|
||||
using TeleWave.Application.Library.Collections;
|
||||
|
||||
namespace TeleWave.Application.Library.GetShow;
|
||||
|
||||
@@ -16,10 +17,28 @@ public sealed class GetShowQueryHandler(IAppDbContext dbContext)
|
||||
var show = await dbContext
|
||||
.Shows.AsNoTracking()
|
||||
.Include(s => s.Episodes)
|
||||
.Include(s => s.Genres)
|
||||
.FirstOrDefaultAsync(s => s.Id == query.Id, cancellationToken);
|
||||
if (show is null)
|
||||
return Result.Failure<ShowDto>(ShowErrors.NotFound);
|
||||
|
||||
var genreIds = show.Genres.Select(g => g.GenreId).ToList();
|
||||
var genreNames = await dbContext
|
||||
.Genres.AsNoTracking()
|
||||
.Where(g => genreIds.Contains(g.Id))
|
||||
.Select(g => new { g.Id, g.Name, g.SortOrder })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var genreDtos = genreNames
|
||||
.OrderByDescending(g => show.Genres.First(sg => sg.GenreId == g.Id).IsPrimary)
|
||||
.ThenBy(g => g.SortOrder)
|
||||
.Select(g => new ShowGenreDto(
|
||||
g.Id,
|
||||
g.Name,
|
||||
show.Genres.First(sg => sg.GenreId == g.Id).IsPrimary
|
||||
))
|
||||
.ToList();
|
||||
|
||||
var episodes = show.Episodes.OrderBy(e => e.Position).ToList();
|
||||
var assetIds = episodes.Select(e => e.MediaAssetId).ToList();
|
||||
var assets = await dbContext
|
||||
@@ -55,6 +74,19 @@ public sealed class GetShowQueryHandler(IAppDbContext dbContext)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var collections = await dbContext
|
||||
.CollectionItems.AsNoTracking()
|
||||
.Where(i => i.ShowId == show.Id)
|
||||
.Join(
|
||||
dbContext.Collections.AsNoTracking(),
|
||||
item => item.CollectionId,
|
||||
collection => collection.Id,
|
||||
(item, collection) =>
|
||||
new ShowCollectionRefDto(collection.Id, collection.Name, item.Position)
|
||||
)
|
||||
.OrderBy(c => c.Name)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return Result.Success(
|
||||
new ShowDto(
|
||||
show.Id,
|
||||
@@ -67,7 +99,9 @@ public sealed class GetShowQueryHandler(IAppDbContext dbContext)
|
||||
show.MetadataExternalId,
|
||||
show.Year,
|
||||
show.PosterImageId,
|
||||
episodeDtos
|
||||
episodeDtos,
|
||||
genreDtos,
|
||||
collections
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user