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:
2026-07-05 04:12:59 +02:00
co-authored by Claude Opus 4.8
parent 6e469dbb4a
commit e802c8565d
46 changed files with 158 additions and 309 deletions
@@ -1,26 +0,0 @@
using ErrorOr;
using Mediator;
using Musify.Application.Users.Responses;
using Musify.Domain.Entities;
namespace Musify.Application.Users.Commands
{
public record CreateUserCommand(long Id,
string Name,
string? FirstName,
string? SecondName)
: ICommand<ErrorOr<UserApplicationResponse>>
{
public static User ToEntity(CreateUserCommand command)
{
return new User
{
Id = command.Id,
Name = command.Name,
NormalizedName = command.Name.ToUpperInvariant(),
FirstName = command.FirstName,
SecondName = command.SecondName
};
}
}
}
@@ -1,13 +0,0 @@
using ErrorOr;
using Mediator;
namespace Musify.Application.Users.Commands
{
public record SyncUserCommand(
long Id,
string Name,
string? FirstName,
string? SecondName,
string? ProfilePictureUrl)
: ICommand<ErrorOr<Success>>;
}
@@ -3,11 +3,30 @@ using Mediator;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Musify.Application.Contracts;
using Musify.Application.Users.Commands;
using Musify.Application.Users.Responses;
using Musify.Domain.Entities;
namespace Musify.Application.Users.Handlers
namespace Musify.Application.Users
{
public record CreateUserCommand(long Id,
string Name,
string? FirstName,
string? SecondName)
: ICommand<ErrorOr<UserApplicationResponse>>
{
public static User ToEntity(CreateUserCommand command)
{
return new User
{
Id = command.Id,
Name = command.Name,
NormalizedName = command.Name.ToUpperInvariant(),
FirstName = command.FirstName,
SecondName = command.SecondName
};
}
}
public class CreateUserCommandHandler(IDatabase database, ILogger<CreateUserCommandHandler> logger)
: ICommandHandler<CreateUserCommand, ErrorOr<UserApplicationResponse> >
{
@@ -37,4 +56,4 @@ namespace Musify.Application.Users.Handlers
return UserApplicationResponse.FromEntity(newUser);
}
}
}
}
@@ -2,11 +2,13 @@ using ErrorOr;
using Mediator;
using Microsoft.EntityFrameworkCore;
using Musify.Application.Contracts;
using Musify.Application.Users.Queries;
using Musify.Application.Users.Responses;
namespace Musify.Application.Users.Handlers
namespace Musify.Application.Users
{
public record GetUserByIdQuery(long Id)
: IQuery<ErrorOr<UserApplicationResponse> >;
public class GetUserByIdQueryHandler(IDatabase database)
: IQueryHandler<GetUserByIdQuery, ErrorOr<UserApplicationResponse> >
{
@@ -24,4 +26,4 @@ namespace Musify.Application.Users.Handlers
return user;
}
}
}
}
@@ -2,13 +2,15 @@ using ErrorOr;
using Mediator;
using Microsoft.EntityFrameworkCore;
using Musify.Application.Pagination;
using Musify.Application.Users.Queries;
using Musify.Application.Users.Responses;
using X.PagedList.EF;
using Musify.Application.Contracts;
namespace Musify.Application.Users.Handlers
namespace Musify.Application.Users
{
public record GetUsersQuery(int PageNumber, int PageSize, string? UsernameSearch = null)
: IQuery<ErrorOr<PaginatedResponse<UserApplicationResponse> >>;
public class GetUsersQueryHandler(IDatabase database)
: IQueryHandler<GetUsersQuery, ErrorOr<PaginatedResponse<UserApplicationResponse> > >
{
@@ -32,4 +34,4 @@ namespace Musify.Application.Users.Handlers
return PaginatedResponse<UserApplicationResponse>.FromPagedList(pagedUser);
}
}
}
}
@@ -1,9 +0,0 @@
using ErrorOr;
using Mediator;
using Musify.Application.Users.Responses;
namespace Musify.Application.Users.Queries
{
public record GetUserByIdQuery(long Id)
: IQuery<ErrorOr<UserApplicationResponse> >;
}
@@ -1,10 +0,0 @@
using ErrorOr;
using Mediator;
using Musify.Application.Pagination;
using Musify.Application.Users.Responses;
namespace Musify.Application.Users.Queries
{
public record GetUsersQuery(int PageNumber, int PageSize, string? UsernameSearch = null)
: IQuery<ErrorOr<PaginatedResponse<UserApplicationResponse> >>;
}
@@ -3,11 +3,18 @@ using Mediator;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Musify.Application.Contracts;
using Musify.Application.Users.Commands;
using Musify.Domain.Entities;
namespace Musify.Application.Users.Handlers
namespace Musify.Application.Users
{
public record SyncUserCommand(
long Id,
string Name,
string? FirstName,
string? SecondName,
string? ProfilePictureUrl)
: ICommand<ErrorOr<Success>>;
public class SyncUserCommandHandler(IDatabase database, ILogger<SyncUserCommandHandler> logger)
: ICommandHandler<SyncUserCommand, ErrorOr<Success>>
{