mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.2 KiB
30 lines
1.2 KiB
using ErsatzTV.Core.Domain.Scheduling; |
|
using ErsatzTV.Infrastructure.Data; |
|
using Microsoft.EntityFrameworkCore; |
|
|
|
namespace ErsatzTV.Application.Playouts; |
|
|
|
public class GetBlockPlayoutHistoryHandler(IDbContextFactory<TvContext> dbContextFactory) |
|
: IRequestHandler<GetBlockPlayoutHistory, PagedPlayoutHistoryViewModel> |
|
{ |
|
public async Task<PagedPlayoutHistoryViewModel> Handle( |
|
GetBlockPlayoutHistory request, |
|
CancellationToken cancellationToken) |
|
{ |
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
IQueryable<PlayoutHistory> query = dbContext.PlayoutHistory |
|
.AsNoTracking() |
|
.Where(ph => ph.PlayoutId == request.PlayoutId && ph.BlockId == request.BlockId); |
|
|
|
int totalCount = await query.CountAsync(cancellationToken); |
|
|
|
List<PlayoutHistory> allHistory = await query |
|
.OrderBy(ph => ph.Id) |
|
.Skip(request.PageNum * request.PageSize) |
|
.Take(request.PageSize) |
|
.ToListAsync(cancellationToken); |
|
|
|
return new PagedPlayoutHistoryViewModel(totalCount, allHistory.Map(Mapper.ProjectToViewModel).ToList()); |
|
} |
|
}
|
|
|