import { Express , Request , Response } from "express" ; import { createPostHandler , updatePostHandler , getPostHandler , deletePostHandler , } from "./controller/post.controller" ; import { createUserHandler } from "./controller/user.controller" ; import { createUserSessionHandler , invalidateUserSessionHandler , getUserSessionsHandler , } from "./controller/session.controller" ; import { validateRequest , requiresUser } from "./middleware" ; import { createUserSchema , createUserSessionSchema , } from "./schema/user.schema" ; import { createPostSchema , updatePostSchema , deletePostSchema , } from "./schema/post.schema" ; export default function ( app ) { app . get ( "/healthcheck" , ( req , res ) => res . sendStatus ( 200 ) ) ; app . post ( "/api/users" , validateRequest ( createUserSchema ) , createUserHandler ) ; app . post ( "/api/sessions" , validateRequest ( createUserSessionSchema ) , createUserSessionHandler ) ; app . get ( "/api/sessions" , requiresUser , getUserSessionsHandler ) ; app . delete ( "/api/sessions" , requiresUser , invalidateUserSessionHandler ) ; app . post ( "/api/posts" , [ requiresUser , validateRequest ( createPostSchema ) ] , createPostHandler ) ; app . put ( "/api/posts/:postId" , [ requiresUser , validateRequest ( updatePostSchema ) ] , updatePostHandler ) ; app . get ( "/api/posts/:postId" , getPostHandler ) ; app . delete ( "/api/posts/:postId" , [ requiresUser , validateRequest ( deletePostSchema ) ] , deletePostHandler ) ; }