refactor(application): co-locate each command/query with its handler
One file per use case under the feature folder (Tracks/PlayLists/Users), dropping the Commands/Queries/Handlers sub-folders and their namespaces. Each file now holds the record and its handler in namespace Musify.Application.<Feature>; external usings updated accordingly. Build: 0 warnings, 0 errors.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using ErrorOr;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Pagination;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user