First Commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayLists
|
||||
{
|
||||
public record GetPlayListsQuery(int PageNumber = 1, int PageSize = 10)
|
||||
: IRequest<GetPlayListsQuery, Result<PaginatedPlayListResponse>>;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
using X.PagedList.EF;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayLists
|
||||
{
|
||||
public class GetPlayListsQueryHandler(IDatabase database)
|
||||
: IRequestHandler<GetPlayListsQuery, Task<Result<PaginatedPlayListResponse>> >
|
||||
{
|
||||
public async Task<Result<PaginatedPlayListResponse>> Handle(GetPlayListsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var pageNumber = request.PageNumber < 1 ? 1 : request.PageNumber;
|
||||
var pageSize = request.PageSize < 1 ? 10 : request.PageSize;
|
||||
|
||||
var totalCount = await database.PlayLists.CountAsync(cancellationToken);
|
||||
|
||||
var pagedPlayLists = await database.PlayLists
|
||||
.AsNoTracking()
|
||||
.OrderBy(p => p.Id)
|
||||
.Select(p => new PlayListResponse(
|
||||
p.Id,
|
||||
p.Name,
|
||||
p.Description,
|
||||
p.ImageName,
|
||||
p.CreatedDate,
|
||||
p.UpdatedDate))
|
||||
.ToPagedListAsync(pageNumber, pageSize, totalCount, cancellationToken);
|
||||
|
||||
var response = new PaginatedPlayListResponse(
|
||||
pagedPlayLists.ToArray(),
|
||||
pagedPlayLists.PageNumber,
|
||||
pagedPlayLists.PageSize,
|
||||
pagedPlayLists.PageCount,
|
||||
pagedPlayLists.TotalItemCount,
|
||||
pagedPlayLists.HasNextPage,
|
||||
pagedPlayLists.HasPreviousPage);
|
||||
|
||||
return Result.Success(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user