Skip to content

Commit

Permalink
Documented the get all blogs and create new blog routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliviier-dev committed Mar 5, 2024
1 parent b350290 commit 7022e60
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions src/routes/blogRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7022e60

Please sign in to comment.