Build ErsatzTV Image / CI toolchain image resolves (push) Successful in 10s
Build ErsatzTV Image / Delimiter ban (release path) (push) Successful in 14s
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 8m53s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 6m18s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (push) Successful in 6m40s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Skipped
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 5m46s
Co-authored-by: Timothy <timothy@noreply.gitea.tblindustries.be>
36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using static ErsatzTV.Application.MediaCollections.Mapper;
|
|
|
|
namespace ErsatzTV.Application.MediaCollections;
|
|
|
|
public class GetPagedCollectionsHandler(IDbContextFactory<TvContext> dbContextFactory)
|
|
: IRequestHandler<GetPagedCollections, PagedMediaCollectionsViewModel>
|
|
{
|
|
public async Task<PagedMediaCollectionsViewModel> Handle(
|
|
GetPagedCollections request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
|
IQueryable<Collection> query = dbContext.Collections.AsNoTracking();
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.Query))
|
|
{
|
|
query = query.Where(c => EF.Functions.Like(c.Name, $"%{request.Query}%"));
|
|
}
|
|
|
|
// count the SAME query the page is taken from, so the two cannot drift (issues #690, #758)
|
|
int count = await query.CountAsync(cancellationToken);
|
|
|
|
List<MediaCollectionViewModel> page = await query
|
|
.OrderBy(c => c.Name)
|
|
.Skip(request.PageNum * request.PageSize)
|
|
.Take(request.PageSize)
|
|
.ToListAsync(cancellationToken)
|
|
.Map(list => list.Map(ProjectToViewModel).ToList());
|
|
|
|
return new PagedMediaCollectionsViewModel(count, page);
|
|
}
|
|
}
|