public class GetPersonTrusteesRequest : IRequest<Response<GetPersonTrusteesResponse>>
public int PersonId { get; set; }
public class GetPersonTrusteesResponse
public int Id { get; set; }
public string Name { get; set; }
public string Identifier { get; set; }
public Guid PartyId { get; set; }
public bool IsPending { get; set; }
public class GetPersonTrusteesHandler : IRequestHandler<GetPersonTrusteesRequest, Response<GetPersonTrusteesResponse>>
private readonly IAgreementServiceClient _agreementService;
private readonly IPartyServiceClient _partyService;
private readonly IMediator _mediator;
public GetPersonTrusteesHandler(IAgreementServiceClient agreementService, IPartyServiceClient partyService, IMediator mediator)
_agreementService = agreementService;
_partyService = partyService;
public async Task<Response<GetPersonTrusteesResponse>> Handle(GetPersonTrusteesRequest request, CancellationToken cancellationToken)
var trustees = await _agreementService.GetTrusteePrivileges(attorneyPersonId: request.PersonId);
if (trustees is not { Item.Persons.Length: > 0 })
return new NoContent<GetPersonTrusteesResponse>();
var persons = await _partyService.GetPersons(trustees.Item.Persons.Select(x => x.TrusteePersonId).ToArray());
if (persons is not { Success: true })
return new BadRequest<GetPersonTrusteesResponse>("Could not get trustees partyId from personId");
var response = await persons.Item.ToAsyncEnumerable()
.SelectAwait(async person => new GetPersonTrusteesResponse()
Identifier = person.Value.Identifications
.Where(identification => identification.Country.CountryCode == "SE")
.Where(identification => identification.Type == IdentificationTypes.NationalRegistrationNumber)
Name = person.Value.Name,
PartyId = person.Value.PartyId,
IsPending = (await _mediator.Send(
new GetQuestionnairesForPersonRequest { PersonId = person.Value.Id })
).Questionnaires.Any(q => q.Status != Questionnaire.QuestionnaireStatus.Done)