Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement API Endpoint to Create Comment on Blog Post #315

Merged
merged 8 commits into from
Jul 25, 2024
7 changes: 4 additions & 3 deletions contributors.md
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)
2 changes: 0 additions & 2 deletions src/controllers/PaymentLemonSqueezyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import config from "../config";
import { Payment } from "../models/payment";
import AppDataSource from "../data-source";


/**
* @swagger
* /api/v1/payments/lemonsqueezy/initiate:
Expand Down Expand Up @@ -51,7 +50,6 @@ export const makePaymentLemonSqueezy = async (req: Request, res: Response) => {
}
};


/**
* @swagger
* /api/v1/payments/lemonsqueezy/webhook:
Expand Down
33 changes: 33 additions & 0 deletions src/controllers/blogCommentController.ts
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.",
});
}
}
}
}
8 changes: 8 additions & 0 deletions src/routes/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { createBlogController } from "../controllers/createBlogController";
import { BlogController } from "../controllers/BlogController";
import { updateBlogController } from "../controllers/updateBlogController";

import { BlogCommentController } from "../controllers/blogCommentController";
const blogRouter = Router();
const blogController = new BlogController();
const blogCommentController = new BlogCommentController();

/**
* @swagger
Expand Down Expand Up @@ -138,4 +140,10 @@ blogRouter.get(
*/
blogRouter.delete("/:id", blogController.deleteBlogPost.bind(blogController));

blogRouter.post(
"/:id/comment",
authMiddleware,
blogCommentController.createComment.bind(blogCommentController),
);

export { blogRouter };
Loading