├── output.gif
├── config
└── db.config.js
├── package.json
├── services
├── users.service.js
└── posts.service.js
├── README.md
├── index.js
├── controller
├── users.controller.js
└── posts.controller.js
├── routes
├── users.routes.js
└── posts.routes.js
└── database.sql
/output.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/navinballa/nodejs-express-project/HEAD/output.gif
--------------------------------------------------------------------------------
/config/db.config.js:
--------------------------------------------------------------------------------
1 | const { createPool } = require("mysql");
2 | /** Connection pool creation - START */
3 | const db = createPool({
4 | port: 3306,
5 | host: "us-cdbr-east-03.cleardb.com",
6 | user: "b257ae9f95d7dd",
7 | password: "badbc264",
8 | database: "heroku_12f1937794459fe",
9 | connectionLimit: 10,
10 | });
11 | /** Connection pool creation - END */
12 | module.exports = db;
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-posts",
3 | "version": "1.0.0",
4 | "description": "Sample project",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "start": " nodemon index.js"
9 | },
10 | "author": "Govind Satpute",
11 | "license": "ISC",
12 | "dependencies": {
13 | "body-parser": "^1.19.0",
14 | "express": "^4.17.1",
15 | "mysql": "^2.18.1",
16 | "nodemon": "^2.0.7",
17 | "swagger-jsdoc": "^6.0.2",
18 | "swagger-ui-express": "^4.1.6"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/services/users.service.js:
--------------------------------------------------------------------------------
1 | const db = require("../config/db.config");
2 |
3 | exports.register = (data, callback) => {
4 | db.query(
5 | `INSERT INTO users (firstName, lastName, emailId, password) VALUES (?, ?, ?, ?)`,
6 | [data.firstName, data.lastName, data.emailId, data.password],
7 | (error, results, fields) => {
8 | if (error) {
9 | return callback(error);
10 | }
11 | return callback(null, `Registration successful`);
12 | }
13 | );
14 | };
15 |
16 | exports.login = (data, callback) => {
17 | db.query(
18 | `SELECT id FROM users WHERE emailId = ? AND password = ?`,
19 | [data.emailId, data.password],
20 | (error, results, fields) => {
21 | if (error) {
22 | return callback(error);
23 | }
24 | if (results.length > 0) {
25 | return callback(null, "Login success");
26 | } else {
27 | return callback("Invalid credentials");
28 | }
29 | }
30 | );
31 | };
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # A Complete NodeJS RESTAPI Application with Express + MySQL + Swagger
2 | Please refer the below steps to clone & run the project in minutes.
3 |
4 | # Steps
5 | 1) Install VS Code & NodeJS
6 | 2) Open VSCODE & Go to terminal and run the command
7 | `git clone https://github.com/navinballa/nodejs-express-project.git`
8 | 3) Move your terminal path to "nodejs-express-project"
9 | `cd nodejs-express-project`
10 | 4) Install libraries
11 | `npm install`
12 | 6) Run project
13 | `npm start`
14 | your project will be ready on http://localhost:3000/api-docs/
15 |
16 | # Output
17 |
18 |
19 | # If having any issues, you may refer below course to understand things more clearly
20 | https://www.udemy.com/course/nodejs-restapi-its-simple/?referralCode=A78A28965EF8F1D7E7BA
21 |
22 | # Youtube
23 |
25 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const swaggerJsdoc = require("swagger-jsdoc");
3 | const swaggerUi = require("swagger-ui-express");
4 |
5 | const app = express();
6 | const bodyParser = require("body-parser");
7 | const usersRoutes = require("./routes/users.routes");
8 | const postsRoutes = require("./routes/posts.routes");
9 |
10 | app.use(bodyParser.json());
11 |
12 | /** Swagger Initialization - START */
13 | const swaggerOption = {
14 | swaggerDefinition: (swaggerJsdoc.Options = {
15 | info: {
16 | title: "my-posts",
17 | description: "API documentation",
18 | contact: {
19 | name: "Developer",
20 | },
21 | servers: ["http://localhost:3000/"],
22 | },
23 | }),
24 | apis: ["index.js", "./routes/*.js"],
25 | };
26 |
27 | const swaggerDocs = swaggerJsdoc(swaggerOption);
28 | app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
29 | /** Swagger Initialization - END */
30 |
31 | app.use("/users", usersRoutes);
32 | app.use("/posts", postsRoutes);
33 |
34 | app.listen(3000, () => {
35 | console.log("I am ready to lisen you");
36 | });
--------------------------------------------------------------------------------
/controller/users.controller.js:
--------------------------------------------------------------------------------
1 | const usersService = require("../services/users.service");
2 |
3 | exports.register = (req, res, next) => {
4 | // Validation area
5 | const data = {
6 | firstName: req.body.firstName,
7 | lastName: req.body.lastName,
8 | emailId: req.body.emailId,
9 | password: req.body.password,
10 | };
11 | usersService.register(data, (error, results) => {
12 | if (error) {
13 | console.log(error);
14 | return res.status(400).send({ success: 0, data: "Bad request" });
15 | }
16 | return res.status(200).send({
17 | success: 1,
18 | data: results,
19 | });
20 | });
21 | };
22 |
23 | exports.login = (req, res, next) => {
24 | // Validation area
25 | const data = {
26 | emailId: req.body.emailId,
27 | password: req.body.password,
28 | };
29 | usersService.login(data, (error, results) => {
30 | if (error) {
31 | console.log(error);
32 | return res.status(400).send({ success: 0, data: "Bad request" });
33 | }
34 | return res.status(200).send({
35 | success: 1,
36 | data: results,
37 | });
38 | });
39 | };
--------------------------------------------------------------------------------
/routes/users.routes.js:
--------------------------------------------------------------------------------
1 | const usersController = require("../controller/users.controller");
2 |
3 | var express = require("express");
4 |
5 | var router = express.Router();
6 |
7 | router.post("/register", usersController.register);
8 | /**
9 | * @swagger
10 | * /users/register:
11 | * post:
12 | * description: Used to register user
13 | * tags:
14 | * - users
15 | * parameters:
16 | * - in: body
17 | * name: User
18 | * description: User data
19 | * schema:
20 | * type: object
21 | * required:
22 | * - firstName
23 | * - lastName
24 | * - emailId
25 | * - password
26 | * properties:
27 | * firstName:
28 | * type: string
29 | * minLength: 1
30 | * maxLength: 45
31 | * example: Navin
32 | * lastName:
33 | * type: string
34 | * minLength: 1
35 | * maxLength: 45
36 | * example: Balla
37 | * emailId:
38 | * type: string
39 | * minLength: 1
40 | * maxLength: 100
41 | * example: navin@sample.com
42 | * password:
43 | * type: string
44 | * minLength: 1
45 | * maxLength: 45
46 | * example: abcd
47 | * responses:
48 | * '200':
49 | * description: Resource added successfully
50 | * '500':
51 | * description: Internal server error
52 | * '400':
53 | * description: Bad request
54 | */
55 |
56 | router.post("/login", usersController.login);
57 | /**
58 | * @swagger
59 | * /users/login:
60 | * post:
61 | * description: Used to login user
62 | * tags:
63 | * - users
64 | * parameters:
65 | * - in: body
66 | * name: User
67 | * description: User data
68 | * schema:
69 | * type: object
70 | * required:
71 | * - emailId
72 | * - password
73 | * properties:
74 | * emailId:
75 | * type: string
76 | * minLength: 1
77 | * maxLength: 100
78 | * example: navin@sample.com
79 | * password:
80 | * type: string
81 | * minLength: 1
82 | * maxLength: 45
83 | * example: abcd
84 | * responses:
85 | * '200':
86 | * description: Resource added successfully
87 | * '500':
88 | * description: Internal server error
89 | * '400':
90 | * description: Bad request
91 | */
92 |
93 | module.exports = router;
--------------------------------------------------------------------------------
/controller/posts.controller.js:
--------------------------------------------------------------------------------
1 | const postsService = require("../services/posts.service");
2 |
3 | exports.addPost = (req, res, next) => {
4 | const data = {
5 | description: req.body.description,
6 | imagePath: req.body.imagePath,
7 | addedByUserId: req.body.addedByUserId,
8 | };
9 |
10 | postsService.addPost(data, (error, results) => {
11 | if (error) {
12 | console.log(error);
13 | return res.status(400).send({ success: 0, data: "Bad request" });
14 | }
15 | return res.status(200).send({
16 | success: 1,
17 | data: results,
18 | });
19 | });
20 | };
21 |
22 |
23 | exports.getAllPosts = (req, res, next) => {
24 | const data = {};
25 | postsService.getAllPosts(data, (error, results) => {
26 | if (error) {
27 | console.log(error);
28 | return res.status(400).send({ success: 0, data: "Bad request" });
29 | }
30 | return res.status(200).send({
31 | success: 1,
32 | data: results,
33 | });
34 | });
35 | };
36 |
37 | exports.addPostComment = (req, res, next) => {
38 | const data = {
39 | postId: req.body.postId,
40 | comment: req.body.comment,
41 | addedByUserId: req.body.addedByUserId,
42 | };
43 | postsService.addPostComment(data, (error, results) => {
44 | if (error) {
45 | console.log(error);
46 | return res.status(400).send({ success: 0, data: "Bad request" });
47 | }
48 | return res.status(200).send({
49 | success: 1,
50 | data: results,
51 | });
52 | });
53 | };
54 |
55 | exports.getPostAllComments = (req, res, next) => {
56 | const data = {
57 | postId: req.query.postId,
58 | };
59 | postsService.getPostAllComments(data, (error, results) => {
60 | if (error) {
61 | console.log(error);
62 | return res.status(400).send({ success: 0, data: "Bad request" });
63 | }
64 | return res.status(200).send({
65 | success: 1,
66 | data: results,
67 | });
68 | });
69 | };
70 |
71 | exports.likePost = (req, res, next) => {
72 | const data = {
73 | postId: req.body.postId,
74 | };
75 | postsService.likePost(data, (error, results) => {
76 | if (error) {
77 | console.log(error);
78 | return res.status(400).send({ success: 0, data: "Bad request" });
79 | }
80 | return res.status(200).send({
81 | success: 1,
82 | data: results,
83 | });
84 | });
85 | };
86 |
87 | exports.dislikePost = (req, res, next) => {
88 | const data = {
89 | postId: req.body.postId,
90 | };
91 | postsService.dislikePost(data, (error, results) => {
92 | if (error) {
93 | console.log(error);
94 | return res.status(400).send({ success: 0, data: "Bad request" });
95 | }
96 | return res.status(200).send({
97 | success: 1,
98 | data: results,
99 | });
100 | });
101 | };
102 | exports.deletePost = (req, res, next) => {
103 | const data = {
104 | postId: req.query.postId,
105 | };
106 | postsService.deletePost(data, (error, results) => {
107 | if (error) {
108 | console.log(error);
109 | return res.status(400).send({ success: 0, data: "Bad request" });
110 | }
111 | return res.status(200).send({
112 | success: 1,
113 | data: results,
114 | });
115 | });
116 | };
--------------------------------------------------------------------------------
/services/posts.service.js:
--------------------------------------------------------------------------------
1 | const db = require("../config/db.config");
2 |
3 | exports.addPost = (data, callback) => {
4 | db.query(
5 | `INSERT INTO posts (description, imagePath, datetimeCreated, addedByUserId)
6 | VALUES (?, ?, ?, ?)`,
7 | [data.description, data.imagePath, new Date(), data.addedByUserId],
8 | (error, results, fields) => {
9 | if (error) {
10 | return callback(error);
11 | }
12 | return callback(null, "Post added successfully");
13 | }
14 | );
15 | };
16 |
17 | exports.getAllPosts = (data, callback) => {
18 | db.query(
19 | `SELECT p.id AS postId, p.description, p.datetimeCreated,
20 | p.likeCount, p.dislikeCount, p.addedByUserId, u.firstName, u.lastName
21 | FROM posts AS p INNER JOIN users AS u ON p.addedByUserId = u.id`,
22 | [],
23 | (error, results, fields) => {
24 | if (error) {
25 | return callback(error);
26 | }
27 | return callback(null, results);
28 | }
29 | );
30 | };
31 |
32 | exports.addPostComment = (data, callback) => {
33 | db.query(
34 | `INSERT INTO comments (postId, comment, datetimeCreated, addedByUserId) VALUES (?, ?, ?, ?)`,
35 | [data.postId, data.comment, new Date(), data.addedByUserId],
36 | (error, results, fields) => {
37 | if (error) {
38 | return callback(error);
39 | }
40 | return callback(null, `Comment Added Successfully`);
41 | }
42 | );
43 | };
44 |
45 | exports.getPostAllComments = (data, callback) => {
46 | db.query(
47 | `SELECT c.comment, c.datetimeCreated, c.addedByUserId, u.firstName, u.lastName
48 | FROM comments AS c INNER JOIN users AS u ON c.addedByUserId = u.id
49 | WHERE c.postId = ?`,
50 | [data.postId],
51 | (error, results, fields) => {
52 | if (error) {
53 | return callback(error);
54 | }
55 | return callback(null, results);
56 | }
57 | );
58 | };
59 | exports.likePost = (data, callback) => {
60 | db.query(
61 | `UPDATE posts
62 | SET
63 | likeCount = likeCount + 1
64 | WHERE
65 | id = ?`,
66 | [data.postId],
67 | (error, results, fields) => {
68 | if (error) {
69 | return callback(error);
70 | }
71 | if (results.affectedRows === 1) {
72 | return callback(null, `Like Successful`);
73 | } else {
74 | return callback(new Error("Invalid post"));
75 | }
76 | }
77 | );
78 | };
79 |
80 | exports.dislikePost = (data, callback) => {
81 | db.query(
82 | `UPDATE posts
83 | SET
84 | dislikeCount = dislikeCount + 1
85 | WHERE
86 | id = ?`,
87 | [data.postId],
88 | (error, results, fields) => {
89 | if (error) {
90 | return callback(error);
91 | }
92 | if (results.affectedRows === 1) {
93 | return callback(null, `Dislike Successful`);
94 | } else {
95 | return callback(new Error("Invalid post"));
96 | }
97 | }
98 | );
99 | };
100 |
101 | exports.deletePost = (data, callback) => {
102 | db.query(
103 | `DELETE FROM posts
104 | WHERE id = ?`,
105 | [data.postId],
106 | (error, results, fields) => {
107 | if (error) {
108 | return callback(error);
109 | }
110 | if (results.affectedRows === 1) {
111 | return callback(null, `Post Deleted Successfully`);
112 | } else {
113 | return callback(new Error("Invalid post"));
114 | }
115 | }
116 | );
117 | };
--------------------------------------------------------------------------------
/database.sql:
--------------------------------------------------------------------------------
1 | CREATE DATABASE IF NOT EXISTS `heroku_12f1937794459fe` /*!40100 DEFAULT CHARACTER SET utf8 */;
2 | USE `heroku_12f1937794459fe`;
3 | -- MySQL dump 10.13 Distrib 8.0.21, for Win64 (x86_64)
4 | --
5 | -- Host: us-cdbr-east-03.cleardb.com Database: heroku_12f1937794459fe
6 | -- ------------------------------------------------------
7 | -- Server version 5.6.50-log
8 |
9 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
10 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
11 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
12 | /*!50503 SET NAMES utf8 */;
13 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
14 | /*!40103 SET TIME_ZONE='+00:00' */;
15 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
16 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
17 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
18 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
19 |
20 | --
21 | -- Table structure for table `comments`
22 | --
23 |
24 | DROP TABLE IF EXISTS `comments`;
25 | /*!40101 SET @saved_cs_client = @@character_set_client */;
26 | /*!50503 SET character_set_client = utf8mb4 */;
27 | CREATE TABLE `comments` (
28 | `id` int(11) NOT NULL AUTO_INCREMENT,
29 | `postId` int(11) NOT NULL,
30 | `comment` varchar(1000) NOT NULL,
31 | `datetimeCreated` datetime NOT NULL,
32 | `addedByUserId` int(11) NOT NULL,
33 | PRIMARY KEY (`id`),
34 | KEY `addedByUserId1_idx` (`postId`),
35 | KEY `addedByUserIdFk1_idx` (`addedByUserId`),
36 | CONSTRAINT `addedByUserIdFk1` FOREIGN KEY (`addedByUserId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
37 | CONSTRAINT `postFk2` FOREIGN KEY (`postId`) REFERENCES `posts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
38 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
39 | /*!40101 SET character_set_client = @saved_cs_client */;
40 |
41 | --
42 | -- Dumping data for table `comments`
43 | --
44 |
45 | LOCK TABLES `comments` WRITE;
46 | /*!40000 ALTER TABLE `comments` DISABLE KEYS */;
47 | /*!40000 ALTER TABLE `comments` ENABLE KEYS */;
48 | UNLOCK TABLES;
49 |
50 | --
51 | -- Table structure for table `posts`
52 | --
53 |
54 | DROP TABLE IF EXISTS `posts`;
55 | /*!40101 SET @saved_cs_client = @@character_set_client */;
56 | /*!50503 SET character_set_client = utf8mb4 */;
57 | CREATE TABLE `posts` (
58 | `id` int(11) NOT NULL AUTO_INCREMENT,
59 | `description` varchar(1000) NOT NULL,
60 | `imagePath` varchar(1000) NOT NULL,
61 | `likeCount` int(11) NOT NULL DEFAULT '0',
62 | `dislikeCount` int(11) NOT NULL DEFAULT '0',
63 | `datetimeCreated` datetime NOT NULL,
64 | `addedByUserId` int(11) NOT NULL,
65 | PRIMARY KEY (`id`),
66 | KEY `userIdFk1_idx` (`addedByUserId`),
67 | CONSTRAINT `userIdFk1` FOREIGN KEY (`addedByUserId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
68 | ) ENGINE=InnoDB AUTO_INCREMENT=1072 DEFAULT CHARSET=utf8;
69 | /*!40101 SET character_set_client = @saved_cs_client */;
70 |
71 | --
72 | -- Dumping data for table `posts`
73 | --
74 |
75 | LOCK TABLES `posts` WRITE;
76 | /*!40000 ALTER TABLE `posts` DISABLE KEYS */;
77 | /*!40000 ALTER TABLE `posts` ENABLE KEYS */;
78 | UNLOCK TABLES;
79 |
80 | --
81 | -- Table structure for table `users`
82 | --
83 |
84 | DROP TABLE IF EXISTS `users`;
85 | /*!40101 SET @saved_cs_client = @@character_set_client */;
86 | /*!50503 SET character_set_client = utf8mb4 */;
87 | CREATE TABLE `users` (
88 | `id` int(11) NOT NULL AUTO_INCREMENT,
89 | `firstName` varchar(45) NOT NULL,
90 | `lastName` varchar(45) NOT NULL,
91 | `emailId` varchar(45) NOT NULL,
92 | `password` varchar(45) NOT NULL,
93 | PRIMARY KEY (`id`),
94 | UNIQUE KEY `emailId_UNIQUE` (`emailId`)
95 | ) ENGINE=InnoDB AUTO_INCREMENT=142 DEFAULT CHARSET=utf8;
96 | /*!40101 SET character_set_client = @saved_cs_client */;
97 |
98 | --
99 | -- Dumping data for table `users`
100 | --
101 |
102 | LOCK TABLES `users` WRITE;
103 | /*!40000 ALTER TABLE `users` DISABLE KEYS */;
104 | /*!40000 ALTER TABLE `users` ENABLE KEYS */;
105 | UNLOCK TABLES;
106 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
107 |
108 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
109 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
110 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
111 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
112 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
113 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
114 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
115 |
116 | -- Dump completed on 2021-05-20 20:03:00
117 |
--------------------------------------------------------------------------------
/routes/posts.routes.js:
--------------------------------------------------------------------------------
1 | const postsController = require("../controller/posts.controller");
2 |
3 | var express = require("express");
4 |
5 | var router = express.Router();
6 |
7 | router.post("/add-post", postsController.addPost);
8 | /**
9 | * @swagger
10 | * /posts/add-post:
11 | * post:
12 | * description: Used to add post
13 | * tags:
14 | * - posts
15 | * parameters:
16 | * - in: body
17 | * name: Post
18 | * description: Post data
19 | * schema:
20 | * type: object
21 | * required:
22 | * - description
23 | * - imagePath
24 | * - addedByUserId
25 | * properties:
26 | * description:
27 | * type: string
28 | * minLength: 1
29 | * maxLength: 1000
30 | * example: This is sample post
31 | * imagePath:
32 | * type: string
33 | * minLength: 1
34 | * maxLength: 1000
35 | * example: abc.png
36 | * addedByUserId:
37 | * type: integer
38 | * example: 1
39 | * responses:
40 | * '200':
41 | * description: Resource added successfully
42 | * '500':
43 | * description: Internal server error
44 | * '400':
45 | * description: Bad request
46 | */
47 | router.get("/get-all-posts", postsController.getAllPosts);
48 | /**
49 | * @swagger
50 | * /posts/get-all-posts:
51 | * get:
52 | * description: Used to get all posts
53 | * tags:
54 | * - posts
55 | * responses:
56 | * '200':
57 | * description: Resource added successfully
58 | * '500':
59 | * description: Internal server error
60 | * '400':
61 | * description: Bad request
62 | */
63 |
64 | router.post("/add-post-comment", postsController.addPostComment);
65 | /**
66 | * @swagger
67 | * /posts/add-post-comment:
68 | * post:
69 | * description: Used to add post comment
70 | * tags:
71 | * - posts
72 | * parameters:
73 | * - in: body
74 | * name: Comment
75 | * description: Post Comment
76 | * schema:
77 | * type: object
78 | * required:
79 | * - postId
80 | * - comment
81 | * - addedByUserId
82 | * properties:
83 | * postId:
84 | * type: integer
85 | * example: 1
86 | * comment:
87 | * type: string
88 | * minLength: 1
89 | * maxLength: 1000
90 | * example: This is sample comment
91 | * addedByUserId:
92 | * type: integer
93 | * example: 1
94 | * responses:
95 | * '200':
96 | * description: Resource added successfully
97 | * '500':
98 | * description: Internal server error
99 | * '400':
100 | * description: Bad request
101 | */
102 | router.get("/get-post-all-comments", postsController.getPostAllComments);
103 | /**
104 | * @swagger
105 | * /posts/get-post-all-comments:
106 | * get:
107 | * description: Used to get all comment of given post id
108 | * tags:
109 | * - posts
110 | * parameters:
111 | * - in: query
112 | * name: postId
113 | * type: integer
114 | * description: Post id
115 | * required: true
116 | * responses:
117 | * '200':
118 | * description: Resource added successfully
119 | * '500':
120 | * description: Internal server error
121 | * '400':
122 | * description: Bad request
123 | */
124 |
125 | router.put("/like-post", postsController.likePost);
126 | /**
127 | * @swagger
128 | * /posts/like-post:
129 | * put:
130 | * description: Used to like post
131 | * tags:
132 | * - posts
133 | * parameters:
134 | * - in: body
135 | * name: Post
136 | * description: Post data
137 | * schema:
138 | * type: object
139 | * required:
140 | * - postId
141 | * properties:
142 | * postId:
143 | * type: integer
144 | * example: 1
145 | * responses:
146 | * '200':
147 | * description: Resource added successfully
148 | * '500':
149 | * description: Internal server error
150 | * '400':
151 | * description: Bad request
152 | */
153 |
154 | router.put("/dislike-post", postsController.dislikePost);
155 | /**
156 | * @swagger
157 | * /posts/dislike-post:
158 | * put:
159 | * description: Used to dilike post
160 | * tags:
161 | * - posts
162 | * parameters:
163 | * - in: body
164 | * name: Post
165 | * description: Post data
166 | * schema:
167 | * type: object
168 | * required:
169 | * - postId
170 | * properties:
171 | * postId:
172 | * type: integer
173 | * example: 1
174 | * responses:
175 | * '200':
176 | * description: Resource added successfully
177 | * '500':
178 | * description: Internal server error
179 | * '400':
180 | * description: Bad request
181 | */
182 | router.delete("/delete-post", postsController.deletePost);
183 | /**
184 | * @swagger
185 | * /posts/delete-post:
186 | * delete:
187 | * description: Used to delete post
188 | * tags:
189 | * - posts
190 | * parameters:
191 | * - in: query
192 | * name: postId
193 | * type: integer
194 | * description: Post id
195 | * required: true
196 | * responses:
197 | * '200':
198 | * description: Resource added successfully
199 | * '500':
200 | * description: Internal server error
201 | * '400':
202 | * description: Bad request
203 | */
204 | module.exports = router;
--------------------------------------------------------------------------------