Move
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayListById
|
||||
{
|
||||
public class GetPlayListByIdQueryHandler(IDatabase database)
|
||||
: IRequestHandler<GetPlayListByIdQuery, Task<Result<PlayListResponse>> >
|
||||
{
|
||||
public async Task<Result<PlayListResponse>> Handle(GetPlayListByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var playList = await database.PlayLists
|
||||
.AsNoTracking()
|
||||
.SingleOrDefaultAsync(p => p.Id == request.Id, cancellationToken);
|
||||
|
||||
return playList is not null
|
||||
? Result.Success(PlayListResponse.FromEntity(playList))
|
||||
: Result.NotFound("Playlist not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
using Musify.Application.PlayLists.Responses;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayListById
|
||||
namespace Musify.Application.PlayLists.Queries
|
||||
{
|
||||
public record GetPlayListByIdQuery(Guid Id)
|
||||
: IRequest<GetPlayListByIdQuery, Task<Result<PlayListResponse>>>;
|
||||
@@ -1,39 +0,0 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts.Application;
|
||||
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<PaginatedResponse<PlayListResponse> >> >
|
||||
{
|
||||
public async Task<Result<PaginatedResponse<PlayListResponse> >> 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 => PlayListResponse.FromEntity(p))
|
||||
.ToPagedListAsync(pageNumber, pageSize, totalCount, cancellationToken);
|
||||
|
||||
var response = new PaginatedResponse<PlayListResponse>(
|
||||
pagedPlayLists.ToArray(),
|
||||
pagedPlayLists.PageNumber,
|
||||
pagedPlayLists.PageSize,
|
||||
pagedPlayLists.PageCount,
|
||||
pagedPlayLists.TotalItemCount,
|
||||
pagedPlayLists.HasNextPage,
|
||||
pagedPlayLists.HasPreviousPage);
|
||||
|
||||
return Result.Success(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts.Application;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
using X.PagedList.EF;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayListsByUserId
|
||||
{
|
||||
public class GetPlayListsByUserIdQueryHandler(IDatabase database)
|
||||
: IRequestHandler<GetPlayListsByUserIdQuery, Task<Result<PaginatedResponse<PlayListResponse> > >>
|
||||
{
|
||||
public async Task<Result<PaginatedResponse<PlayListResponse> >> Handle(GetPlayListsByUserIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var pageNumber = request.PageNumber < 1 ? 1 : request.PageNumber;
|
||||
var pageSize = request.PageSize < 1 ? 10 : request.PageSize;
|
||||
var normalizedName = request.Name?.Trim().ToUpperInvariant() ?? string.Empty;
|
||||
|
||||
var playListsQuery = database.PlayLists
|
||||
.AsNoTracking()
|
||||
.Where(p => p.UserId == request.UserId);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(normalizedName))
|
||||
playListsQuery = playListsQuery.Where(p => p.NormalizedName.Contains(normalizedName));
|
||||
|
||||
var totalCount = await playListsQuery.CountAsync(cancellationToken);
|
||||
|
||||
var pagedPlayLists = await playListsQuery
|
||||
.OrderBy(p => p.CreatedDate)
|
||||
.Select(p => PlayListResponse.FromEntity(p))
|
||||
.ToPagedListAsync(pageNumber, pageSize, totalCount, cancellationToken);
|
||||
|
||||
var response = new PaginatedResponse<PlayListResponse>(
|
||||
pagedPlayLists.ToArray(),
|
||||
pagedPlayLists.PageNumber,
|
||||
pagedPlayLists.PageSize,
|
||||
pagedPlayLists.PageCount,
|
||||
pagedPlayLists.TotalItemCount,
|
||||
pagedPlayLists.HasNextPage,
|
||||
pagedPlayLists.HasPreviousPage);
|
||||
|
||||
return Result.Success(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Musify.Application.Contracts.Application;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
using Musify.Application.PlayLists.Responses;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayListsByUserId
|
||||
namespace Musify.Application.PlayLists.Queries
|
||||
{
|
||||
public record GetPlayListsByUserIdQuery(
|
||||
Guid UserId,
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
using Ardalis.Result;
|
||||
using DispatchR.Abstractions.Send;
|
||||
using Musify.Application.Contracts.Application;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
using Musify.Application.PlayLists.Responses;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayLists
|
||||
namespace Musify.Application.PlayLists.Queries
|
||||
{
|
||||
public record GetPlayListsQuery(int PageNumber = 1, int PageSize = 10)
|
||||
: IRequest<GetPlayListsQuery, Task<Result<PaginatedResponse<PlayListResponse>> >>;
|
||||
Reference in New Issue
Block a user