Files
mws.backend.dotnet/mws.application/Accounts/Queries/GetAccounts.cs
T
namdhandClaude Sonnet 5 50faf9052c 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>
2026-08-14 08:38:31 +07:00

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);
}
}