File size: 1,570 Bytes
3d23b0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import { FastifyPluginAsync } from 'fastify';
import * as handlers from './handlers';
import * as schemas from './schemas';
import validateUsername from '../../shared/middlewares/validate';
import type {
UserQuery,
SubmissionsQuery,
UserPostsQuery,
LeaderboardQuery,
PromotionalEventsQuery
} from './types';
const gfgRoutes: FastifyPluginAsync = async (fastify) => {
// Legacy mapping (GET for consistency with other platforms)
fastify.get<{ Querystring: UserQuery }>(
'/rating',
{
preHandler: [validateUsername],
schema: schemas.userRatingSchema,
},
handlers.getUserRatingHandler
);
// New APIs
fastify.post<{ Body: SubmissionsQuery }>(
'/submissions',
{
schema: schemas.userSubmissionsSchema,
},
handlers.getUserSubmissionsHandler
);
fastify.get<{ Params: { username: string }, Querystring: Omit<UserPostsQuery, 'username'> }>(
'/posts/:username',
{
schema: schemas.userPostsSchema,
},
handlers.getUserPostsHandler
);
fastify.get<{ Querystring: PromotionalEventsQuery }>(
'/events/promotional',
{
schema: schemas.promotionalEventsSchema,
},
handlers.getPromotionalEventsHandler
);
fastify.get<{ Querystring: LeaderboardQuery }>(
'/leaderboard',
{
schema: schemas.contestLeaderboardSchema,
},
handlers.getContestLeaderboardHandler
);
};
export default gfgRoutes;
|