feat(web,api): added ability to add and then display list of institutions

This commit is contained in:
Stevan Freeborn
2026-02-22 06:53:13 -06:00
parent b4fbf16869
commit fd2cd68d73
11 changed files with 364 additions and 70 deletions
@@ -0,0 +1,34 @@
namespace FiscalOS.API.Institutions.Get;
internal static class Endpoint
{
private const string Route = "/";
public static RouteHandlerBuilder MapGetEndpoint(this RouteGroupBuilder groupBuilder)
{
return groupBuilder.MapGet(Route, HandleAsync);
}
private static async Task<IResult> HandleAsync(
HttpContext httpContext,
[FromServices] AppDbContext appDbContext
)
{
var userId = httpContext.GetUserId();
var user = await appDbContext.Users
.Include(u => u.Institutions)
.FirstOrDefaultAsync(u => u.Id == userId);
if (user is null)
{
return Results.Unauthorized();
}
var institutionDtos = user.Institutions
.Select(InstitutionDto.FromInstitution)
.OrderBy(dto => dto.Name);
return Results.Ok(Response.From(institutionDtos));
}
}