Skip to content

Commit 79fd8c3

Browse files
authored
Merge pull request #100 from estyemma/route
feat/Add creator public route name constants
2 parents e92ca09 + e5f1463 commit 79fd8c3

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/constants/creator-public-cache.constants.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Reuses shared TTLs from {@link PUBLIC_ENDPOINT_CACHE_SECONDS} where appropriate.
55
*/
66
import { PUBLIC_ENDPOINT_CACHE_SECONDS } from './public-endpoint-cache.constants';
7+
import { CREATOR_PUBLIC_ROUTE_NAMES } from './creator-public-routes.constants';
78

89
/**
910
* Max-age (seconds) for public creator GET responses (list, profile, stats).
@@ -18,15 +19,15 @@ const publicReadSeconds = CREATOR_PUBLIC_ROUTE_CACHE_MAX_AGE_SECONDS.publicRead;
1819
* Options for {@link cacheControl} on creator public routes.
1920
*/
2021
export const CREATOR_PUBLIC_ROUTE_CACHE_PRESETS = {
21-
creatorList: {
22+
[CREATOR_PUBLIC_ROUTE_NAMES.LIST]: {
2223
maxAge: publicReadSeconds,
2324
type: 'public' as const,
2425
},
25-
creatorStats: {
26+
[CREATOR_PUBLIC_ROUTE_NAMES.GET_STATS]: {
2627
maxAge: publicReadSeconds,
2728
type: 'public' as const,
2829
},
29-
creatorProfile: {
30+
[CREATOR_PUBLIC_ROUTE_NAMES.GET_PROFILE]: {
3031
maxAge: publicReadSeconds,
3132
type: 'public' as const,
3233
},
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Shared route name constants for creator-facing public API endpoints.
3+
*
4+
* These constants provide stable identifiers for public creator routes,
5+
* allowing related modules (controllers, tests, client-side) to reference
6+
* routes by name instead of hardcoded strings.
7+
*/
8+
export const CREATOR_PUBLIC_ROUTE_NAMES = {
9+
/** GET /api/v1/creators - Paginated list of creators */
10+
LIST: 'creators:list',
11+
/** GET /api/v1/creators/:creatorId/profile - Public profile details */
12+
GET_PROFILE: 'creators:profile:get',
13+
/** PUT /api/v1/creators/:creatorId/profile - Upsert profile (scaffold) */
14+
UPSERT_PROFILE: 'creators:profile:upsert',
15+
/** GET /api/v1/creators/:creatorId/stats - Public creator stats */
16+
GET_STATS: 'creators:stats:get',
17+
} as const;

src/modules/creator/creator.routes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { ROOT as CREATORS_ROOT } from '../../constants/creator.constants';
99
import { cacheControl } from '../../middlewares/cache-control.middleware';
1010
import { CREATOR_PUBLIC_ROUTE_CACHE_PRESETS } from '../../constants/creator-public-cache.constants';
11+
import { CREATOR_PUBLIC_ROUTE_NAMES } from '../../constants/creator-public-routes.constants';
1112

1213
const router = Router();
1314

@@ -29,7 +30,7 @@ const router = Router();
2930
*/
3031
router.get(
3132
CREATORS_ROOT,
32-
cacheControl(CREATOR_PUBLIC_ROUTE_CACHE_PRESETS.creatorList),
33+
cacheControl(CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.LIST]),
3334
listCreators
3435
);
3536

@@ -40,7 +41,7 @@ router.get(
4041
*/
4142
router.get(
4243
'/:creatorId/profile',
43-
cacheControl(CREATOR_PUBLIC_ROUTE_CACHE_PRESETS.creatorProfile),
44+
cacheControl(CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.GET_PROFILE]),
4445
getCreatorProfileHandler
4546
);
4647

src/modules/creators/creators.routes.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Router } from 'express';
2-
import { httpListCreators } from './creators.controllers';
2+
import { httpListCreators, httpGetCreatorStats } from './creators.controllers';
33
import { cacheControl } from '../../middlewares/cache-control.middleware';
44
import { CREATOR_PUBLIC_ROUTE_CACHE_PRESETS } from '../../constants/creator-public-cache.constants';
5+
import { CREATOR_PUBLIC_ROUTE_NAMES } from '../../constants/creator-public-routes.constants';
56

67
const creatorsRouter = Router();
78

@@ -13,8 +14,20 @@ const creatorsRouter = Router();
1314
*/
1415
creatorsRouter.get(
1516
'/',
16-
cacheControl(CREATOR_PUBLIC_ROUTE_CACHE_PRESETS.creatorList),
17+
cacheControl(CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.LIST]),
1718
httpListCreators
1819
);
1920

21+
/**
22+
* GET /api/v1/creators/:id/stats
23+
*
24+
* Get public stats for a specific creator.
25+
* Public endpoint with 5-minute cache.
26+
*/
27+
creatorsRouter.get(
28+
'/:id/stats',
29+
cacheControl(CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.GET_STATS]),
30+
httpGetCreatorStats
31+
);
32+
2033
export default creatorsRouter;

0 commit comments

Comments
 (0)