Summary endpoint for the operations dashboard
C# · ASP.NET Core · advanced · greenfield
Adds the summary endpoint the new operations dashboard polls. `DashboardController` (new) serves `GET /api/dashboard/summary`: it starts the order stats call and the helpdesk call together, waits for both, and combines their results into the new `DashboardSummary` record (`DashboardSummary.cs`). It passes the request's abort token to both calls, and an upstream failure surfaces through the existing exception handler as a 500. `DashboardSummaryTests.cs` adds xUnit tests on `WebApplicationFactory<Program>` with in-memory fakes for the two clients: the combined body, an upstream failure and the sign-in requirement.
ASP.NET Core 10 Web API on .NET 10 (C# 14, nullable reference types enabled, implicit usings), controllers with `[ApiController]`. Production runs the API as a single instance: one Linux container with 2 vCPUs (`Environment.ProcessorCount` is 2), with the runtime's default thread pool settings (no `SetMinThreads` anywhere). Existing and unchanged, all registered in `Program.cs`: `IOrderStatsClient` and `IHelpdeskClient` are typed `HttpClient`s (`AddHttpClient`, 5-second timeout), async throughout. `GetTodayTotalsAsync(ct)` returns `OrderTotals(int OrderCount, long RevenueCents)` from the internal analytics service, which aggregates on the fly and answers in 300 to 800 ms, about 500 ms typically. `GetOpenTicketCountsAsync(ct)` returns `TicketCounts(int Open, int Urgent)` from the helpdesk in 100 to 400 ms. Both throw `HttpRequestException` on a network error or a non-2xx answer. `UseExceptionHandler()` with `AddProblemDetails()` turns any unhandled exception into a generic 500 problem response and logs it. Staff sign in with JWT bearer tokens. The existing test project `tests/Shop.Api.Tests` (xUnit, references `Microsoft.AspNetCore.Mvc.Testing`) signs staff in through a test authentication scheme that `Program.cs` registers outside Production: a request with an `X-Test-Staff: <id>` header is a signed-in staff member, and every existing integration test uses it. `MapHealthChecks("/health")` serves the load balancer's probe. Every existing controller action that does I/O is `async Task<...>` and takes a `CancellationToken`. JSON uses the ASP.NET Core web defaults (camelCase). The dashboard page ships separately and only reads this endpoint.
Requirements
- New endpoint `GET /api/dashboard/summary` returns `{ "ordersToday", "revenueTodayCents", "openTickets", "urgentTickets" }` for the new operations dashboard: today's order count and revenue from the order stats service (`IOrderStatsClient.GetTodayTotalsAsync`) and the open and urgent ticket counts from the helpdesk (`IHelpdeskClient.GetOpenTicketCountsAsync`).
- The two upstream calls do not depend on each other, so they run at the same time: a summary should take about as long as the slower of the two calls, not their sum.
- Load: about 400 screens show the dashboard (warehouse wall monitors and staff browsers) and each one refreshes the summary every 30 seconds, so the endpoint gets about 13 requests a second during opening hours. It must hold up at that rate on the API's single instance, answering in about the time of its slower upstream call, without slowing the API's other endpoints (picking, order lookups, the load balancer's `/health` probe).
- The request's cancellation token is passed to both upstream calls, so a dashboard that closes or navigates away stops waiting for them.
- If either upstream call fails, the endpoint answers the API's generic 500 problem response (no partial summary). Like the API's other controllers, the endpoint requires signed-in staff (`[Authorize]`, 401 otherwise).
Files touched
- src/Shop.Api/Dashboard/DashboardController.cs
- src/Shop.Api/Dashboard/DashboardSummary.cs
- tests/Shop.Api.Tests/DashboardSummaryTests.cs