Newest members card on the workspace home page

C# · ASP.NET Core · beginner · modification

Adds the data behind the new "New members" card on the workspace home page. `Members/NewestMembersEndpoint.cs` maps `GET /api/workspaces/{workspaceId}/members/newest` behind the `WorkspaceMember` policy and reads the workspace's memberships with one EF Core query, capped at `Limit` (20) and projected straight into `NewestMemberDto`, so `Email` and the other membership columns never leave the database. `Program.cs` registers the endpoint next to the existing workspace routes.

ASP.NET Core 10 minimal APIs on .NET 10 (C# 14, nullable reference types and implicit usings enabled), EF Core 10 with Npgsql on PostgreSQL 16. `AppDbContext` (existing, unchanged) has `DbSet<Membership> Memberships`; `Membership` has `int Id` (identity), `int WorkspaceId`, `int UserId`, `string DisplayName`, `string Email` and `DateTime JoinedAt`, stored as `timestamptz` and read back as UTC. A membership row exists only while the user is a member (leaving deletes it), a workspace has at most 5,000 members, and there is an index on `(WorkspaceId, JoinedAt)`. `AddWorkspaceAuth` and the `WorkspaceMember` policy (existing, unchanged) sign the user in from the session cookie and succeed only when the signed-in user has a membership in the `workspaceId` route value; otherwise the request gets 401 (not signed in) or 403 before the handler runs. `MapWorkspaces`, the exception handler and `AddProblemDetails` are unchanged; a database error surfaces as the usual 500 problem response. The web app's card ships separately and shows the items in the order the endpoint returns them. The API tests (xUnit + `WebApplicationFactory`) cover the existing workspace routes; this PR adds none.

Requirements

Files touched

--- src/Workspaces.Api/Program.cs
 using Workspaces.Api.Auth;
 using Workspaces.Api.Data;
+using Workspaces.Api.Members;
 using Workspaces.Api.Workspaces;
 
 
 app.MapWorkspaces();
+app.MapNewestMembers();
 
 app.Run();
--- src/Workspaces.Api/Members/NewestMembersEndpoint.cs
+using Microsoft.EntityFrameworkCore;
+using Workspaces.Api.Data;
+
+namespace Workspaces.Api.Members;
+
+public static class NewestMembersEndpoint
+{
+    public const int Limit = 20;
+
+    public static IEndpointRouteBuilder MapNewestMembers(this IEndpointRouteBuilder app)
+    {
+        app.MapGet("/api/workspaces/{workspaceId:int}/members/newest", GetNewestAsync)
+            .RequireAuthorization("WorkspaceMember");
+        return app;
+    }
+
+    private static async Task<List<NewestMemberDto>> GetNewestAsync(
+        int workspaceId, AppDbContext db, CancellationToken ct)

Review this PR

C# practice