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.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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user