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>
23 lines
766 B
C#
23 lines
766 B
C#
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);
|
|
}
|
|
}
|