Convert Accounts module to MediatR commands/queries
Replaces IAccountService/AccountService with one command/query per operation, following the pattern set in the Auth module. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using Mws.Application.Common;
|
||||
using Mws.Application.Permissions;
|
||||
|
||||
namespace Mws.Application.Accounts;
|
||||
|
||||
public record GetAccountsQuery(Guid ActorUserId, string? Term) : IRequest<List<AccountDto>>;
|
||||
|
||||
public class GetAccountsHandler(IUnitOfWork uow, IPermissionService permissions, IMapper mapper)
|
||||
: IRequestHandler<GetAccountsQuery, List<AccountDto>>
|
||||
{
|
||||
private const string Screen = "accounts";
|
||||
|
||||
public async Task<List<AccountDto>> Handle(GetAccountsQuery query, CancellationToken ct)
|
||||
{
|
||||
await permissions.EnsureAsync(query.ActorUserId, Screen, PermissionAction.View, ct);
|
||||
|
||||
var users = await uow.Users.SearchWithRoleAsync(query.Term, null, ct);
|
||||
return mapper.Map<List<AccountDto>>(users);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user