chore: import MusifyBackend into monorepo (preserving history)
git-subtree-dir: MusifyBackend git-subtree-mainline:6829e769edgit-subtree-split:ed7b00c2cc
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using Ardalis.Result;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Pagination;
|
||||
using Musify.Application.PlayLists.Responses;
|
||||
using Musify.Application.PlayLists.Queries;
|
||||
using X.PagedList.EF;
|
||||
using Mediator;
|
||||
using Musify.Application.Contracts;
|
||||
|
||||
namespace Musify.Application.PlayLists.Handlers
|
||||
{
|
||||
public class GetPlayListsByUserIdQueryHandler(IDatabase database)
|
||||
: IQueryHandler<GetPlayListsByUserIdQuery, Result<PaginatedResponse<PlayListApplicationResponse> > >
|
||||
{
|
||||
public async ValueTask<Result<PaginatedResponse<PlayListApplicationResponse> >> Handle(GetPlayListsByUserIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var playListsQuery = database.PlayLists
|
||||
.AsNoTracking()
|
||||
.Where(p => p.UserId == request.UserId);
|
||||
|
||||
if (request.Name is not null)
|
||||
{
|
||||
var normalizedName = request.Name.Trim().ToUpperInvariant();
|
||||
playListsQuery = playListsQuery.Where(p => p.NormalizedName.Contains(normalizedName));
|
||||
}
|
||||
|
||||
var totalCount = await playListsQuery.CountAsync(cancellationToken);
|
||||
|
||||
var pagedPlayLists = await playListsQuery
|
||||
.OrderBy(p => p.CreatedAt)
|
||||
.Select(p => PlayListApplicationResponse.FromEntity(p))
|
||||
.ToPagedListAsync(request.PageNumber, request.PageSize, totalCount, cancellationToken);
|
||||
|
||||
return Result.Success(PaginatedResponse<PlayListApplicationResponse>.FromPagedList(pagedPlayLists));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user