From 7022e606a6f5714ceb87e01275b425232ad9fb75 Mon Sep 17 00:00:00 2001 From: Olivier BYIRINGIRO Date: Tue, 5 Mar 2024 20:07:18 +0200 Subject: [PATCH] Documented the get all blogs and create new blog routes --- src/routes/blogRoutes.ts | 144 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/src/routes/blogRoutes.ts b/src/routes/blogRoutes.ts index 637d9ad..5204603 100644 --- a/src/routes/blogRoutes.ts +++ b/src/routes/blogRoutes.ts @@ -5,6 +5,59 @@ import schemaValidator from "../middleware/schemaValidator"; const router = express.Router(); +/** + * @swagger + * /api/blog/blogs: + * get: + * summary: Get all blogs + * description: Retrieve a list of all blogs. + * responses: + * 200: + * description: A list of blogs + * content: + * application/json: + * schema: + * type: array + * items: + * type: object + * properties: + * _id: + * type: string + * description: The unique identifier for the blog. + * title: + * type: string + * description: The title of the blog. + * snippet: + * type: string + * description: A short snippet or summary of the blog. + * category: + * type: string + * description: The category of the blog. + * imageUrl: + * type: string + * description: The URL of the image associated with the blog. + * author: + * type: string + * description: The author of the blog. + * body: + * type: string + * description: The main content or body of the blog. + * likes: + * type: array + * description: An array of user IDs who liked the blog. + * items: + * type: string + * comments: + * type: array + * description: An array of comment IDs associated with the blog. + * items: + * type: string + * createdAt: + * type: string + * format: date-time + * description: The date and time when the blog was created. + */ + // Get a list of blogs from the db router.get('/blogs', async (req: Request, res: Response, next: NextFunction) => { try { @@ -38,6 +91,97 @@ router.post('/createnew', schemaValidator("/blog/createnew"), requireAuth, isAdm } }); + + + +/** + * @swagger + * /api/blog/createnew: + * post: + * summary: Create a new blog + * description: Create a new blog post and add it to the database. + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * title: + * type: string + * description: The title of the blog. + * snippet: + * type: string + * description: A short snippet or summary of the blog. + * category: + * type: string + * description: The category of the blog. + * imageUrl: + * type: string + * description: The URL of the image associated with the blog. + * author: + * type: string + * description: The author of the blog. + * body: + * type: string + * description: The main content or body of the blog. + * responses: + * 201: + * description: Blog created successfully + * content: + * application/json: + * schema: + * type: object + * properties: + * _id: + * type: string + * description: The unique identifier for the blog. + * title: + * type: string + * description: The title of the blog. + * snippet: + * type: string + * description: A short snippet or summary of the blog. + * category: + * type: string + * description: The category of the blog. + * imageUrl: + * type: string + * description: The URL of the image associated with the blog. + * author: + * type: string + * description: The author of the blog. + * body: + * type: string + * description: The main content or body of the blog. + * likes: + * type: array + * description: An array of user IDs who liked the blog. + * items: + * type: string + * comments: + * type: array + * description: An array of comment IDs associated with the blog. + * items: + * type: string + * createdAt: + * type: string + * format: date-time + * description: The date and time when the blog was created. + * 400: + * description: Bad request. Invalid data provided. + * 401: + * description: Unauthorized. User is not authenticated. + * 403: + * description: Forbidden. User is not authorized to create a blog. + * 500: + * description: Internal server error. Failed to create the blog. + */ + + + // Update a blog in the db router.put('/blogs/:id', requireAuth, isAdmin, async (req: Request, res: Response, next: NextFunction) => { try {