* start to add multi-collections * create multi collection with no items * edit multi collections * fix plex credentials threading issue * add playback order to multi collection items * group episodes outside of shuffled enumerator * move playback order onto each schedule item * fix multi collection grouping * update changelog
52 lines
2.1 KiB
C#
52 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using LanguageExt;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using static ErsatzTV.Application.ProgramSchedules.Mapper;
|
|
|
|
namespace ErsatzTV.Application.ProgramSchedules.Queries
|
|
{
|
|
public class GetProgramScheduleItemsHandler :
|
|
IRequestHandler<GetProgramScheduleItems, List<ProgramScheduleItemViewModel>>
|
|
{
|
|
private readonly IDbContextFactory<TvContext> _dbContextFactory;
|
|
|
|
public GetProgramScheduleItemsHandler(IDbContextFactory<TvContext> dbContextFactory) =>
|
|
_dbContextFactory = dbContextFactory;
|
|
|
|
public async Task<List<ProgramScheduleItemViewModel>> Handle(
|
|
GetProgramScheduleItems request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
await using TvContext dbContext = _dbContextFactory.CreateDbContext();
|
|
return await dbContext.ProgramScheduleItems
|
|
.Filter(psi => psi.ProgramScheduleId == request.Id)
|
|
.Include(i => i.Collection)
|
|
.Include(i => i.MultiCollection)
|
|
.Include(i => i.MediaItem)
|
|
.ThenInclude(i => (i as Movie).MovieMetadata)
|
|
.ThenInclude(mm => mm.Artwork)
|
|
.Include(i => i.MediaItem)
|
|
.ThenInclude(i => (i as Season).SeasonMetadata)
|
|
.ThenInclude(sm => sm.Artwork)
|
|
.Include(i => i.MediaItem)
|
|
.ThenInclude(i => (i as Season).Show)
|
|
.ThenInclude(s => s.ShowMetadata)
|
|
.ThenInclude(sm => sm.Artwork)
|
|
.Include(i => i.MediaItem)
|
|
.ThenInclude(i => (i as Show).ShowMetadata)
|
|
.ThenInclude(sm => sm.Artwork)
|
|
.Include(i => i.MediaItem)
|
|
.ThenInclude(i => (i as Artist).ArtistMetadata)
|
|
.ThenInclude(am => am.Artwork)
|
|
.ToListAsync(cancellationToken)
|
|
.Map(programScheduleItems => programScheduleItems.Map(ProjectToViewModel).ToList());
|
|
}
|
|
}
|
|
}
|