Closes #616
This PR introduces the per-developer usage summary endpoint (GET /api/developers/me/usage/summary) for the GrantFox FWC26 campaign. It provides authenticated developers with an aggregate snapshot of call volume, revenue, active API count, per-API breakdown, and time-series buckets over configurable time periods (day, week, month).
-
Route Handler (
src/routes/developers/me/usage.ts):- Implemented
createDeveloperMeUsageRouterhandlingGET /summary. - Added strict authentication requirement using
requireAuth. - Added developer profile resolution (
developerRepository.findByUserId), returning403 ForbiddenwithDEVELOPER_NOT_FOUNDcode if missing. - Implemented input boundary validation for
fromandtoISO timestamps (from <= to),groupByenum ('day','week','month'), andapiIdownership check (usageEventsRepository.developerOwnsApi). - Aggregated metrics (
totalCalls,totalRevenue,activeApis,breakdownByApi, andbuckets). - Added structured logging with correlation IDs.
- Implemented
-
Router Mounting (
src/routes/developerRoutes.ts,src/index.ts):- Mounted
createDeveloperMeUsageRouterat/me/usageincreateDeveloperRouter. - Passed
usageEventsRepositorytocreateDeveloperRouterinsrc/index.ts.
- Mounted
-
API Documentation (
docs/openapi.json):- Documented path
/api/developers/me/usage/summaryunderpathswith tags, parameters, and response codes. - Added
DeveloperUsageSummaryResponseschema tocomponents/schemas.
- Documented path
-
Testing (
src/routes/developers/me/usage.test.ts):- Added comprehensive test suite covering unauthenticated access (401), missing profile (403 DEVELOPER_NOT_FOUND), invalid dates/range/groupBy/apiId (400/403), zero usage (200), multi-API usage aggregations (200), week/month time buckets, and API filtering.
- Implementation matches issue description
- Minimum 90% test coverage on changed lines
- Input validation at boundary & standardized error envelope
- Structured logging with correlation IDs
- OpenAPI documentation updated
- All tests created and passing