Files
mws.backend.dotnet/mws.application/Accounts/Queries/GetAccounts.cs
T

23 lines
766 B
C#
Raw Normal View History

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