First Commit

This commit is contained in:
2026-03-18 01:14:49 +01:00
commit 28719fe4d1
39 changed files with 1361 additions and 0 deletions
@@ -0,0 +1,12 @@
namespace Musify.Application.PlayLists.Contracts
{
public record PaginatedPlayListResponse(
IReadOnlyCollection<PlayListResponse> PlayLists,
int PageNumber,
int PageSize,
int PageCount,
int TotalItemCount,
bool HasNextPage,
bool HasPreviousPage
);
}
@@ -0,0 +1,10 @@
namespace Musify.Application.PlayLists.Contracts
{
public record PlayListResponse(
Guid Id,
string Name,
string Description,
string ImageName,
DateTime CreatedAt,
DateTime UpdatedAt);
}
@@ -0,0 +1,9 @@
using Ardalis.Result;
using DispatchR.Abstractions.Send;
using Musify.Application.PlayLists.Contracts;
namespace Musify.Application.PlayLists.Queries.GetPlayListById
{
public record GetPlayListByIdQuery(Guid Id)
: IRequest<GetPlayListByIdQuery, Result<PlayListResponse>>;
}
@@ -0,0 +1,29 @@
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(new PlayListResponse(
playList.Id,
playList.Name,
playList.Description,
playList.ImageName,
playList.CreatedDate,
playList.UpdatedDate))
: Result.NotFound("Playlist not found.");
}
}
}
@@ -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);
}
}
}
@@ -0,0 +1,13 @@
using Ardalis.Result;
using DispatchR.Abstractions.Send;
using Musify.Application.PlayLists.Contracts;
namespace Musify.Application.PlayLists.Queries.GetPlayListsByUserId
{
public record GetPlayListsByUserIdQuery(
Guid UserId,
string Name = "",
int PageNumber = 1,
int PageSize = 10)
: IRequest<GetPlayListsByUserIdQuery, Result<PaginatedPlayListResponse>>;
}
@@ -0,0 +1,51 @@
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.GetPlayListsByUserId
{
public class GetPlayListsByUserIdQueryHandler(IDatabase database)
: IRequestHandler<GetPlayListsByUserIdQuery, Task<Result<PaginatedPlayListResponse>> >
{
public async Task<Result<PaginatedPlayListResponse>> 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();
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 => 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);
}
}
}