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.
25 lines
998 B
25 lines
998 B
using ErsatzTV.Infrastructure.Data; |
|
using Microsoft.EntityFrameworkCore; |
|
|
|
namespace ErsatzTV.Application.Scheduling; |
|
|
|
public class GetTemplateItemsHandler(IDbContextFactory<TvContext> dbContextFactory) |
|
: IRequestHandler<GetTemplateItems, List<TemplateItemViewModel>> |
|
{ |
|
public async Task<List<TemplateItemViewModel>> Handle(GetTemplateItems request, CancellationToken cancellationToken) |
|
{ |
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
// drop items that are invalid |
|
return await dbContext.TemplateItems |
|
.AsNoTracking() |
|
.Filter(i => i.TemplateId == request.TemplateId) |
|
.Include(i => i.Block) |
|
.ToListAsync(cancellationToken) |
|
.Map( |
|
items => items |
|
.Map(Mapper.ProjectToViewModel) |
|
.Filter(i => i.StartTime < i.EndTime || i.EndTime.TimeOfDay == TimeSpan.Zero) |
|
.ToList()); |
|
} |
|
}
|
|
|