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. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Application.Tracks.Responses;
|
||||
|
||||
namespace Musify.Application.Tracks
|
||||
{
|
||||
public record GetTrackByIdQuery(Guid TrackId)
|
||||
: IQuery<ErrorOr<TrackApplicationResponse>>;
|
||||
|
||||
public class GetTrackByIdQueryHandler(IDatabase database)
|
||||
: IQueryHandler<GetTrackByIdQuery, ErrorOr<TrackApplicationResponse> >
|
||||
{
|
||||
public async ValueTask<ErrorOr<TrackApplicationResponse>> Handle(GetTrackByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var track = await database.Tracks.AsNoTracking()
|
||||
.Where(t => t.Id == request.TrackId)
|
||||
.Select(t => TrackApplicationResponse.FromEntity(t))
|
||||
.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (track is null)
|
||||
return Error.NotFound();
|
||||
|
||||
return track;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user