-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from myconpeter/MYCON
feat: Implement API Endpoint to Create Comment on Blog Post
- Loading branch information
Showing
4 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- [Nainah23](https://github.com/Nainah23) | ||
- Erasmus Tayviah (StarmannRassy) | ||
- [Adekolu Samuel Samixx](https://github.com/samixYasuke) | ||
[Nainah23](https://github.com/Nainah23) | ||
Erasmus Tayviah (StarmannRassy) | ||
[Adekolu Samuel Samixx](https://github.com/samixYasuke) | ||
[Micheal Peter] (https://github.com/myconpeter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Request, Response } from "express"; | ||
import { createComment } from "../services/blogComment.services"; | ||
|
||
export class BlogCommentController { | ||
async createComment(req: Request, res: Response) { | ||
const blogId = req.params.blogId; | ||
const { content } = req.body; | ||
|
||
try { | ||
const comment = await createComment(blogId, content); | ||
res.status(201).json({ | ||
status: "success", | ||
status_code: 201, | ||
message: "Comment created successfully.", | ||
data: comment, | ||
}); | ||
} catch (error: any) { | ||
if (error.message === "Blog not found") { | ||
res.status(404).json({ | ||
status: "unsuccessful", | ||
status_code: 404, | ||
message: error.message, | ||
}); | ||
} else { | ||
res.status(500).json({ | ||
status: "unsuccessful", | ||
status_code: 500, | ||
message: "Failed to create comment. Please try again later.", | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters