feat(api): include accounts in institution dto
This commit is contained in:
@@ -18,6 +18,7 @@ internal static class Endpoint
|
||||
|
||||
var user = await appDbContext.Users
|
||||
.Include(u => u.Institutions)
|
||||
.ThenInclude(i => i.Accounts)
|
||||
.FirstOrDefaultAsync(u => u.Id == userId);
|
||||
|
||||
if (user is null)
|
||||
@@ -26,7 +27,7 @@ internal static class Endpoint
|
||||
}
|
||||
|
||||
var institutionDtos = user.Institutions
|
||||
.Select(InstitutionDto.FromInstitution)
|
||||
.Select(InstitutionDto.From)
|
||||
.OrderBy(dto => dto.Name);
|
||||
|
||||
return Results.Ok(Response.From(institutionDtos));
|
||||
|
||||
@@ -18,22 +18,44 @@ internal sealed record Response
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed record AccountDto
|
||||
{
|
||||
public string Id { get; init; } = string.Empty;
|
||||
public string Name { get; init; } = string.Empty;
|
||||
|
||||
[JsonConstructor]
|
||||
private AccountDto()
|
||||
{
|
||||
}
|
||||
|
||||
public static AccountDto From(Account account)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = account.Id.ToString(),
|
||||
Name = account.Name,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed record InstitutionDto
|
||||
{
|
||||
public string Id { get; init; } = string.Empty;
|
||||
public string Name { get; init; } = string.Empty;
|
||||
public IEnumerable<AccountDto> Accounts { get; init; } = [];
|
||||
|
||||
[JsonConstructor]
|
||||
private InstitutionDto()
|
||||
{
|
||||
}
|
||||
|
||||
public static InstitutionDto FromInstitution(Institution institution)
|
||||
public static InstitutionDto From(Institution institution)
|
||||
{
|
||||
return new InstitutionDto
|
||||
return new()
|
||||
{
|
||||
Id = institution.Id.ToString(),
|
||||
Name = institution.Name,
|
||||
Accounts = institution.Accounts.Select(AccountDto.From),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user