feat(api): include accounts in institution dto

This commit is contained in:
Stevan Freeborn
2026-02-24 06:55:37 -06:00
parent 2fa34fe5ab
commit 81c45350e8
4 changed files with 38 additions and 10 deletions
@@ -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));
+24 -2
View File
@@ -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),
};
}
}