- Move PaginatedResponse from the single-file Pagination/ folder into Shared/ (namespace Musify.Application.Pagination -> Musify.Application.Shared) - Rename MusifyApplication.cs -> AssemblyInfo.cs (it only holds the [assembly: MediatorOptions] attribute) Build: 0 warnings, 0 errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using ErrorOr;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Musify.Application.Shared;
|
|
using Musify.Application.PlayLists.Responses;
|
|
using X.PagedList.EF;
|
|
using Mediator;
|
|
using Musify.Application.Contracts;
|
|
|
|
namespace Musify.Application.PlayLists
|
|
{
|
|
public record GetPlayListsQuery(int PageNumber = 1, int PageSize = 10)
|
|
: IQuery<ErrorOr<PaginatedResponse<PlayListApplicationResponse>> >;
|
|
|
|
public class GetPlayListsQueryHandler(IDatabase database)
|
|
: IQueryHandler<GetPlayListsQuery, ErrorOr<PaginatedResponse<PlayListApplicationResponse> >>
|
|
{
|
|
public async ValueTask<ErrorOr<PaginatedResponse<PlayListApplicationResponse> >> Handle(GetPlayListsQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var totalCount = await database.PlayLists.CountAsync(cancellationToken);
|
|
|
|
var pagedPlayLists = await database.PlayLists
|
|
.AsNoTracking()
|
|
.OrderBy(p => p.Id)
|
|
.Select(p => PlayListApplicationResponse.FromEntity(p))
|
|
.ToPagedListAsync(request.PageNumber, request.PageSize, totalCount, cancellationToken);
|
|
|
|
return PaginatedResponse<PlayListApplicationResponse>.FromPagedList(pagedPlayLists);
|
|
}
|
|
}
|
|
}
|