Skip to content

Commit

Permalink
Merge pull request #315 from myconpeter/MYCON
Browse files Browse the repository at this point in the history
feat: Implement API Endpoint to Create Comment on Blog Post
  • Loading branch information
incredible-phoenix246 authored Jul 25, 2024
2 parents adba118 + adb1950 commit 924d396
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
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 };

0 comments on commit 924d396

Please sign in to comment.