diff --git a/Procfile b/Procfile
deleted file mode 100644
index 489b270..0000000
--- a/Procfile
+++ /dev/null
@@ -1 +0,0 @@
-web: node server.js
diff --git a/README.md b/README.md
index 80cabfc..3b50fef 100755
--- a/README.md
+++ b/README.md
@@ -8,18 +8,17 @@ Node API is production ready and open source project in Node, Express and MongoD
### Documentation
-Swagger Docs https://rest-api-node.herokuapp.com/docs/
+Swagger Docs https://rest-api-node-413916.uc.r.appspot.com/docs/
### Support
-This application is hosted on Heroku and serve a bunch of AJAX requests to give and manipulate data from database and give a support to test front end applications
+This application is hosted on Google Cloud Platfom and serve a bunch of AJAX requests to give and manipulate data from database and give a support to test front end applications
### Servers
-| Server | Description | Api Url | Branch (GitHub) |
-| ---------- | ----------------- | ---------------------------------------------- | --------------- |
-| staging | Open Api | https://rest-api-node.herokuapp.com | master |
-| production | Authenticated Api | https://rest-api-node-production.herokuapp.com | production |
+| Server | Description | Api Url |
+| ---------- | ------------------------------------- | --------------------------------------------- |
+| App Engine | Rest API Node - Google Cloud Platform | https://rest-api-node-413916.uc.r.appspot.com |
### Showcase
@@ -33,23 +32,23 @@ This application is hosted on Heroku and serve a bunch of AJAX requests to give
#### Projects
-| URL | Collection | Method | Parameters | Response | Action |
-| ------------------------------------------------------- | ---------- | ------ | ---------- | --------------------------------------- | ------------------------------------------- |
-| https://rest-api-node.herokuapp.com/projects | projects | get | Nothing | JSON with Array | Get a list of projects in the database |
-| https://rest-api-node.herokuapp.com/projects/create | projects | post | JSON | JSON | Add JSON into the database |
-| https://rest-api-node.herokuapp.com/projects/update/:id | projects | put | id, JSON | Update the document with sent JSON data |
-| https://rest-api-node.herokuapp.com/projects/select/:id | projects | get | id | JSON | Return the document, related to the sent id |
-| https://rest-api-node.herokuapp.com/projects/delete/:id | projects | delete | id | status 200 | Delete the document, related to the sent id |
+| URL | Collection | Method | Parameters | Response | Action |
+| ----------------------------------------------------------------- | ---------- | ------ | ---------- | --------------------------------------- | ------------------------------------------- |
+| https://rest-api-node-413916.uc.r.appspot.com/projects | projects | get | Nothing | JSON with Array | Get a list of projects in the database |
+| https://rest-api-node-413916.uc.r.appspot.com/projects/create | projects | post | JSON | JSON | Add JSON into the database |
+| https://rest-api-node-413916.uc.r.appspot.com/projects/update/:id | projects | put | id, JSON | Update the document with sent JSON data |
+| https://rest-api-node-413916.uc.r.appspot.com/projects/select/:id | projects | get | id | JSON | Return the document, related to the sent id |
+| https://rest-api-node-413916.uc.r.appspot.com/projects/delete/:id | projects | delete | id | status 200 | Delete the document, related to the sent id |
#### Users
-| URL | Collection | Method | Parameters | Response | Action |
-| ---------------------------------------------------- | ---------- | ------ | ---------- | --------------- | ------------------------------------------- |
-| https://rest-api-node.herokuapp.com/users | users | get | Nothing | JSON with Array | Get a list of users in the database |
-| https://rest-api-node.herokuapp.com/users/create | users | post | JSON | JSON | Add JSON into the database |
-| https://rest-api-node.herokuapp.com/users/update/:id | users | put | id | JSON | Update the document with sent JSON data |
-| https://rest-api-node.herokuapp.com/users/select/:id | users | get | id | JSON | Return the document, related to the sent id |
-| https://rest-api-node.herokuapp.com/users/delete/:id | users | delete | id | status 200 | Delete the document, related to the sent id |
+| URL | Collection | Method | Parameters | Response | Action |
+| -------------------------------------------------------------- | ---------- | ------ | ---------- | --------------- | ------------------------------------------- |
+| https://rest-api-node-413916.uc.r.appspot.com/users | users | get | Nothing | JSON with Array | Get a list of users in the database |
+| https://rest-api-node-413916.uc.r.appspot.com/users/create | users | post | JSON | JSON | Add JSON into the database |
+| https://rest-api-node-413916.uc.r.appspot.com/users/update/:id | users | put | id | JSON | Update the document with sent JSON data |
+| https://rest-api-node-413916.uc.r.appspot.com/users/select/:id | users | get | id | JSON | Return the document, related to the sent id |
+| https://rest-api-node-413916.uc.r.appspot.com/users/delete/:id | users | delete | id | status 200 | Delete the document, related to the sent id |
## Collections
@@ -79,15 +78,16 @@ This application is hosted on Heroku and serve a bunch of AJAX requests to give
## API
-| Technology | Description | Link |
-| ---------------- | ----------------------- | ------------ |
-| Heroku | Cloud Platform | [heroku.com] |
-| Heroku mLab Dyno | MongoDB database server | [mlab.com] |
-| GitHub | Version Controlling | [github.com] |
+| Technology | Description | Link |
+| ------------- | ----------------------- | ------------------ |
+| AppEngine | Google Cloud Platform | [cloud.google.com] |
+| MongoDB Atlas | MongoDB database server | [mongodb.com] |
+| GitHub | Version Controlling | [github.com] |
## API Directories
-- Routes `./src/routes`
+- Public Routes `./src/routes/public`
+- Private Routes `./src/routes/private`
- Models `./src/app/Models`
- Controllers `./src/app/Controllers`
- Services `./src/app/Services`
@@ -112,7 +112,8 @@ AUTH_SECRET=docssecret
```
- Run the server npm start
-- Access in your browser http://localhost:3000/projects
+- Access in your browser http://localhost:8080/projects
+- For deployment is important to update app.yaml to your service_account and can be found on your GCP
## API Dependencies
diff --git a/app.yaml b/app.yaml
new file mode 100644
index 0000000..f54fcf1
--- /dev/null
+++ b/app.yaml
@@ -0,0 +1,29 @@
+runtime: nodejs
+api_version: "1.0"
+env: flexible
+threadsafe: true
+automatic_scaling:
+ cool_down_period_sec: 180
+ min_num_instances: 1
+ max_num_instances: 2
+ cpu_utilization:
+ target_utilization: 0.9
+network:
+ name: default
+resources:
+ cpu: 2
+ memory_gb: 4.6
+ disk_size_gb: 10
+liveness_check:
+ initial_delay_sec: "300"
+ check_interval_sec: "30"
+ timeout_sec: "4"
+ failure_threshold: 4
+ success_threshold: 2
+readiness_check:
+ check_interval_sec: "5"
+ timeout_sec: "4"
+ failure_threshold: 2
+ success_threshold: 2
+ app_start_timeout_sec: "300"
+service_account: rest-api-node-413916@appspot.gserviceaccount.com
diff --git a/package.json b/package.json
index 2a68a61..6dc9f26 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,11 @@
{
"name": "node_api",
- "version": "4.14.0",
+ "version": "5.16.0",
"description": "Node API is production ready and open source project in Node, Express, MongoDB",
"scripts": {
- "start": "node server.js"
+ "gcp-build": "",
+ "start": "node server.js",
+ "deploy": "gcloud app deploy app.yaml --version=0-1-3"
},
"author": "Renan Lopes",
"license": "MIT",
@@ -19,8 +21,5 @@
"nodemailer": "^6.9.9",
"swagger-jsdoc": "^4.3.2",
"swagger-ui-express": "^4.1.6"
- },
- "engines": {
- "node": "18.x"
}
}
diff --git a/server.js b/server.js
index a226204..f7aba89 100644
--- a/server.js
+++ b/server.js
@@ -57,7 +57,7 @@ class App {
};
buildCluster = () => {
- let workers = Number(process.env.WORKERS ?? 1);
+ let workers = Number(process.env.WORKERS || 1);
if (process.env.AUTO_SCALE === "true") {
workers = this.autoScale(workers);
diff --git a/src/app/Controllers/AuthController.js b/src/app/Controllers/AuthController.js
index 05b25ed..b6d1f53 100644
--- a/src/app/Controllers/AuthController.js
+++ b/src/app/Controllers/AuthController.js
@@ -4,46 +4,57 @@ const jwt = require("jsonwebtoken");
const model = mongoose.model("User");
class AuthController {
- login = async (req, res) => {
+ login = async (request, response) => {
try {
- const user = await model.findOne({ email: req.body.email });
- const match = await bcrypt.compareSync(req.body.password, user.password);
+ const user = await model.findOne({ email: request.body.email });
+ const match = await bcrypt.compareSync(
+ request.body.password,
+ user.password
+ );
- let token;
if (!match) {
- res.status(401).send({ error: "error", message: "Password mismatch" });
- token = jwt.sign({ user_id: user._id }, process.env.AUTH_SECRET, {
- expiresIn: "3h",
- });
+ response
+ .status(401)
+ .send({ error: "error", message: "Password mismatch" });
}
- res.status(200).json({
+ const token = jwt.sign({ user_id: user._id }, process.env.AUTH_SECRET, {
+ expiresIn: "3h",
+ });
+
+ response.status(200).json({
_id: user._id,
nickname: user.nickname,
username: user.username,
photo: user.photo,
email: user.email,
- token: token,
+ token,
});
} catch (error) {
- res
+ response
.status(401)
.json({ error: error, message: "Error, user does not exists" });
}
};
- verifyToken = (req, res, next) => {
- const token = req.get("Authorization");
- if (token) {
+ verifyToken = (request, response, next) => {
+ const bearerFormat = request.get("authorization");
+
+ if (bearerFormat) {
+ const token = bearerFormat.split(" ")[1];
+
try {
- let decoded = jwt.verify(token, process.env.AUTH_SECRET);
- req.user = decoded;
- next();
+ const decoded = jwt.verify(token, process.env.AUTH_SECRET);
+ request.user = decoded;
+
+ return next();
} catch (error) {
- res.status(401).json({ error: error, message: "Invalid Token" });
+ return response
+ .status(401)
+ .json({ error: error, message: "Invalid Token" });
}
} else {
- res.status(401).json("Token is required");
+ response.status(401).json("Token is required");
}
};
}
diff --git a/src/app/Controllers/ProjectController.js b/src/app/Controllers/ProjectController.js
index f0ce224..263dba4 100644
--- a/src/app/Controllers/ProjectController.js
+++ b/src/app/Controllers/ProjectController.js
@@ -2,49 +2,50 @@ const mongoose = require("mongoose");
const model = mongoose.model("Project");
class ProjectController {
- async getAllProjects(_, res) {
+ async getAllProjects(request, response) {
try {
const projects = await model.find({});
- res.status(200).json(projects);
+ return response.status(200).json(projects);
} catch (error) {
- res.status(500).json(error);
+ return response.status(500).json(error);
}
}
- async createProject(req, res) {
+ async createProject(request, response) {
try {
- const user = await model.create(req.body);
- res.json(user);
+ const user = await model.create(request.body);
+ return response.json(user);
} catch (error) {
- res.status(500).json(error);
+ return response.status(500).json(error);
}
}
- async updateProject(req, res) {
- const { params, body } = req;
+ async updateProject(request, response) {
+ const { params, body } = request;
try {
const project = await model.findByIdAndUpdate(params.id, body);
- res.status(200).json(project);
+ return response.status(200).json(project);
} catch (error) {
- res.status(404).json(error);
+ return response.status(404).json(error);
}
}
- async searchProjectById(req, res) {
+ async searchProjectById(request, response) {
try {
- const project = await model.findById(req.params.id);
- res.status(200).json(project);
+ const project = await model.findById(request.params.id);
+ return response.status(200).json(project);
} catch (error) {
- res.status(404).json(error);
+ return response.status(404).json(error);
}
}
- async deleteProjectById(req, res) {
+ async deleteProjectById(request, response) {
try {
- await model.remove({ _id: req.params.id });
- res.status(200);
+ await model.deleteOne({ _id: request.params.id });
+
+ return response.status(200).json({ message: "Deleted successfully" });
} catch (error) {
- res.status(404).json(error);
+ return response.status(404).json(error);
}
}
}
diff --git a/src/app/Controllers/UserController.js b/src/app/Controllers/UserController.js
index 2b6efa2..0f94f52 100644
--- a/src/app/Controllers/UserController.js
+++ b/src/app/Controllers/UserController.js
@@ -6,7 +6,7 @@ const MailerService = require("../Services/Mail");
class UserController {
hashPassword = (password) => {
- const saltRounds = bcrypt.genSaltSync(process.env.AUTH_ROUNDS);
+ const saltRounds = bcrypt.genSaltSync(Number(process.env.AUTH_ROUNDS));
const hashedPassword = bcrypt.hashSync(password, saltRounds);
return hashedPassword;
@@ -17,57 +17,74 @@ class UserController {
MailerService.sendMail(content);
};
- getAllUsers = async (_, res) => {
+ getAllUsers = async (request, response) => {
try {
const users = await model.find({});
- res.status(200).json(users);
+
+ return response.status(200).json(users);
} catch (error) {
- res.status(500).json(error);
+ return response.status(500).json(error);
}
};
- createUser = async (req, res) => {
- const user = req.body;
+ createUser = async (request, response) => {
+ const user = request.body;
try {
user.password = this.hashPassword(user.password);
- console.log(user.password);
+
const newUser = await model.create(user);
this.sendWelcomeEmail(user.email);
- res.status(200).json(newUser);
+
+ return response.status(200).json(newUser);
} catch (error) {
console.log(error);
- res.status(500).json(error);
+ return response.status(500).json(error);
}
};
- updateUser = async (req, res) => {
- const user = req.body;
+ updateUser = async (request, response) => {
+ const userData = request.body;
+
+ // request.user is the authenticated user id
+ if (request.user !== request.params.id) {
+ return response.status(401).send({
+ error: "error",
+ message: "Permission Denied...",
+ });
+ }
+
try {
- user.password = this.hashPassword(user.password);
- await model.findByIdAndUpdate(req.params.id, user);
- res.status(200).json(user);
+ userData.password = this.hashPassword(userData.password);
+
+ await model.findByIdAndUpdate(request.params.id, userData);
+
+ return response.status(200).json(user);
} catch (error) {
- res.status(404).json(error);
+ return response.status(404).json(error);
}
};
- searchUserById = async (req, res) => {
- const { id } = req.params;
+ searchUserById = async (request, response) => {
+ const { id } = request.params;
try {
const user = await model.findById(id);
- res.status(200).json(user);
+
+ let userResponse = Object.assign({}, user._doc);
+ delete userResponse.password;
+
+ return response.status(200).json(userResponse);
} catch (error) {
- res.status(404).json(error);
+ return response.status(404).json(error);
}
};
- deleteUserById = async (req, res) => {
- const { id } = req.params;
+ deleteUserById = async (request, response) => {
+ const { id } = request.params;
try {
- await model.remove({ _id: id });
- res.status(200);
+ await model.deleteOne({ _id: id });
+ return response.status(200).json({ message: "Deleted successfully" });
} catch (error) {
- res.status(404).json(error);
+ return response.status(404).json(error);
}
};
}
diff --git a/src/app/Middleware/AuthMiddleware.js b/src/app/Middleware/AuthMiddleware.js
index 475bdc0..b2a5956 100644
--- a/src/app/Middleware/AuthMiddleware.js
+++ b/src/app/Middleware/AuthMiddleware.js
@@ -1,8 +1,62 @@
+/**
+ * @swagger
+ * paths:
+ * /login:
+ * post:
+ * summary: User login
+ * description: Authenticates a user and returns a token along with user details.
+ * requestBody:
+ * required: true
+ * content:
+ * application/json:
+ * schema:
+ * type: object
+ * required:
+ * - email
+ * - password
+ * properties:
+ * email:
+ * type: string
+ * format: email
+ * description: User's email address.
+ * password:
+ * type: string
+ * description: User's password.
+ * responses:
+ * 200:
+ * description: Login successful, returns user details and token.
+ * content:
+ * application/json:
+ * schema:
+ * type: object
+ * properties:
+ * _id:
+ * type: string
+ * description: The user ID.
+ * nickname:
+ * type: string
+ * description: The user's nickname.
+ * username:
+ * type: string
+ * description: The user's username.
+ * photo:
+ * type: string
+ * description: URL to the user's photo.
+ * email:
+ * type: string
+ * format: email
+ * description: The user's email address.
+ * token:
+ * type: string
+ * description: Bearer token for authenticating future requests.
+ * 401:
+ * description: Unauthorized, invalid email or password.
+ */
+
module.exports = (src) => {
- const { AuthController, UserController } = src.app.Controllers;
+ const { AuthController } = src.app.Controllers;
src.post("/login", AuthController.login);
- src.post("/users/create", UserController.createUser);
// Private Routes
src.use("/*", AuthController.verifyToken);
};
diff --git a/src/app/Models/Project.js b/src/app/Models/Project.js
index bb6f016..b75d724 100755
--- a/src/app/Models/Project.js
+++ b/src/app/Models/Project.js
@@ -1,3 +1,44 @@
+/**
+ * @swagger
+ * components:
+ * schemas:
+ * Project:
+ * type: object
+ * properties:
+ * project:
+ * type: string
+ * description: Name of the project
+ * technologies:
+ * type: string
+ * description: Technologies used in the project
+ * description:
+ * type: string
+ * description: Detailed description of the project
+ * demoLink:
+ * type: string
+ * description: URL to the live demo of the project
+ * githubLink:
+ * type: string
+ * description: URL to the GitHub repository of the project
+ * author:
+ * type: string
+ * description: Name of the project's author
+ * authorLink:
+ * type: string
+ * description: URL to the author's profile or homepage
+ * status:
+ * type: string
+ * description: Current status of the project (e.g., active, completed, on hold)
+ * example:
+ * project: My Awesome Project
+ * technologies: JavaScript, React, Node.js
+ * description: This project is a web application that allows users to...
+ * demoLink: https://demolink.com
+ * githubLink: https://githublink.com
+ * author: Renan
+ * authorLink: https://authorprofile.com
+ * status: Active
+ */
const mongoose = require("mongoose");
const schema = mongoose.Schema({
diff --git a/src/routes/private/project.js b/src/routes/private/project.js
index e68610c..ca87e43 100755
--- a/src/routes/private/project.js
+++ b/src/routes/private/project.js
@@ -1,3 +1,114 @@
+/**
+ * @swagger
+ * components:
+ * securitySchemes:
+ * authorization:
+ * type: http
+ * scheme: bearer
+ * bearerFormat: JWT
+ * schemas:
+ * Project:
+ * type: object
+ * properties:
+ * project:
+ * type: string
+ * description: Name of the project
+ * technologies:
+ * type: string
+ * description: Technologies used in the project
+ * description:
+ * type: string
+ * description: Detailed description of the project
+ * demoLink:
+ * type: string
+ * description: URL to the live demo of the project
+ * githubLink:
+ * type: string
+ * description: URL to the GitHub repository of the project
+ * author:
+ * type: string
+ * description: Name of the project's author
+ * authorLink:
+ * type: string
+ * description: URL to the author's profile or homepage
+ * status:
+ * type: string
+ * description: Current status of the project (e.g., active, completed, on hold)
+ * example:
+ * project: My Awesome Project
+ * technologies: JavaScript, React, Node.js
+ * description: This project is a web application that allows users to...
+ * demoLink: https://demolink.com
+ * githubLink: https://githublink.com
+ * author: Renan
+ * authorLink: https://authorprofile.com
+ * status: Active
+ *
+ * paths:
+ * /projects/create:
+ * post:
+ * summary: Create a project
+ * description: Creates a new project entry.
+ * security:
+ * - authorization: []
+ * requestBody:
+ * required: true
+ * content:
+ * application/json:
+ * schema:
+ * $ref: '#/components/schemas/Project'
+ * responses:
+ * 200:
+ * description: Project created successfully.
+ * 401:
+ * description: Unauthorized if the user is not authenticated.
+ *
+ * /projects/update/{id}:
+ * put:
+ * summary: Update a project
+ * description: Updates an existing project by its ID.
+ * security:
+ * - authorization: []
+ * parameters:
+ * - in: path
+ * name: id
+ * required: true
+ * description: Unique ID of the project to update.
+ * requestBody:
+ * required: true
+ * content:
+ * application/json:
+ * schema:
+ * $ref: '#/components/schemas/Project'
+ * responses:
+ * 200:
+ * description: Project updated successfully.
+ * 400:
+ * description: Bad request if the input data is invalid.
+ * 401:
+ * description: Unauthorized if the user is not authenticated.
+ *
+ * /projects/delete/{id}:
+ * delete:
+ * summary: Delete a project
+ * description: Deletes an existing project by its ID.
+ * security:
+ * - authorization: []
+ * parameters:
+ * - in: path
+ * name: id
+ * required: true
+ * description: Unique ID of the project to delete.
+ * responses:
+ * 200:
+ * description: Project deleted successfully.
+ * 401:
+ * description: Unauthorized if the user is not authenticated.
+ *
+ * security:
+ * - authorization: []
+ */
+
module.exports = (src) => {
const { ProjectController } = src.app.Controllers;
diff --git a/src/routes/private/user.js b/src/routes/private/user.js
index 9fe563f..fb33f43 100755
--- a/src/routes/private/user.js
+++ b/src/routes/private/user.js
@@ -1,37 +1,95 @@
/**
* @swagger
- * tags:
- * name: Users
- * description: User management
- */
-
-/**
- * @swagger
- * path:
- * /users/create:
- * post:
- * summary: Create a new user
- * tags: [Users]
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schema:
- * $ref: '#/components/schemas/User'
- * responses:
- * "200":
- * description: A user schema
- * content:
- * application/json:
- * schema:
- * $ref: '#/components/schemas/User'
+ * components:
+ * securitySchemes:
+ * authorization:
+ * type: http
+ * scheme: bearer
+ * bearerFormat: JWT
+ * schemas:
+ * User:
+ * type: object
+ * required:
+ * - username
+ * - email
+ * - password
+ * properties:
+ * username:
+ * type: string
+ * email:
+ * type: string
+ * format: email
+ * description: Email for the user, needs to be unique.
+ * password:
+ * type: string
+ * photo:
+ * type: string
+ * description: Image URL string
+ * nickname:
+ * type: string
+ * example:
+ * username: Renan
+ * email: fake@email.com
+ * password: 123456aa
+ * nickname: Dexter
+ * photo: https://photourl.com/image.png
+ *
+ * paths:
+ * /users/update/{id}:
+ * put:
+ * summary: Update a user
+ * description: Updates the details of an existing user.
+ * security:
+ * - authorization: []
+ * parameters:
+ * - in: path
+ * name: id
+ * required: true
+ * description: Unique ID of the user to update.
+ * schema:
+ * type: string
+ * requestBody:
+ * required: true
+ * content:
+ * application/json:
+ * schema:
+ * $ref: '#/components/schemas/User'
+ * responses:
+ * 200:
+ * description: User updated successfully.
+ * 400:
+ * description: Bad request if the input data is invalid.
+ * 401:
+ * description: Unauthorized if the user is not authenticated.
+ * 404:
+ * description: User not found.
+ *
+ * /users/delete/{id}:
+ * delete:
+ * summary: Delete a user
+ * description: Deletes an existing user by their ID.
+ * security:
+ * - authorization: []
+ * parameters:
+ * - in: path
+ * name: id
+ * required: true
+ * description: Unique ID of the user to delete.
+ * responses:
+ * 200:
+ * description: User deleted successfully.
+ * 401:
+ * description: Unauthorized if the user is not authenticated.
+ * 404:
+ * description: User not found.
+ *
+ * security:
+ * - authorization: []
*/
module.exports = (src) => {
const { UserController } = src.app.Controllers;
- src.post("/users/create", UserController.createUser);
-
src.put("/users/update/:id", UserController.updateUser);
src.delete("/users/delete/:id", UserController.deleteUserById);
diff --git a/src/routes/public/project.js b/src/routes/public/project.js
index 5dc052b..75cd809 100755
--- a/src/routes/public/project.js
+++ b/src/routes/public/project.js
@@ -1,3 +1,79 @@
+/**
+ * @swagger
+ * paths:
+ * /projects:
+ * get:
+ * summary: Retrieves a list of projects
+ * description: Fetches a list of all projects from the database.
+ * responses:
+ * 200:
+ * description: A list of projects.
+ * content:
+ * application/json:
+ * schema:
+ * type: array
+ * items:
+ * $ref: '#/components/schemas/Project'
+ * /projects/select/{id}:
+ * get:
+ * summary: Searches for a project by ID
+ * description: Returns a single project matching the provided ID.
+ * parameters:
+ * - in: path
+ * name: id
+ * required: true
+ * description: Unique ID of the project to retrieve.
+ * schema:
+ * type: string
+ * responses:
+ * 200:
+ * description: A project object.
+ * content:
+ * application/json:
+ * schema:
+ * $ref: '#/components/schemas/Project'
+ * 404:
+ * description: Project not found.
+ * components:
+ * schemas:
+ * Project:
+ * type: object
+ * properties:
+ * project:
+ * type: string
+ * description: Name of the project.
+ * technologies:
+ * type: string
+ * description: Technologies used in the project.
+ * description:
+ * type: string
+ * description: Detailed description of the project.
+ * demoLink:
+ * type: string
+ * description: URL to the live demo of the project.
+ * githubLink:
+ * type: string
+ * description: URL to the GitHub repository of the project.
+ * author:
+ * type: string
+ * description: Name of the project's author.
+ * authorLink:
+ * type: string
+ * description: URL to the author's profile or homepage.
+ * status:
+ * type: string
+ * description: Current status of the project (e.g., active, completed, on hold).
+ * example:
+ * project: My Awesome Project
+ * technologies: JavaScript, React, Node.js
+ * description: This project is a web application that allows users to...
+ * demoLink: https://demolink.com
+ * githubLink: https://githublink.com
+ * author: Renan
+ * authorLink: https://authorprofile.com
+ * status: Active
+ */
+
module.exports = (src) => {
const { ProjectController } = src.app.Controllers;
diff --git a/src/routes/public/service.js b/src/routes/public/service.js
new file mode 100644
index 0000000..c518c08
--- /dev/null
+++ b/src/routes/public/service.js
@@ -0,0 +1,11 @@
+module.exports = (src) => {
+ src.get("/liveness_check", (req, res) => {
+ // Send a 200 OK response to indicate the service is alive
+ res.status(200).send("OK");
+ });
+
+ src.get("/readiness_check", (req, res) => {
+ // Send a 200 OK response to indicate the service is ready
+ res.status(200).send("OK");
+ });
+};
diff --git a/src/routes/public/user.js b/src/routes/public/user.js
index 7440c7b..3031e0f 100755
--- a/src/routes/public/user.js
+++ b/src/routes/public/user.js
@@ -1,36 +1,90 @@
/**
* @swagger
- * tags:
- * name: Users
- * description: User management
- */
-
-/**
- * @swagger
- * path:
- * /users/create:
- * post:
- * summary: Create a new user
- * tags: [Users]
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schema:
- * $ref: '#/components/schemas/User'
- * responses:
- * "200":
- * description: A user schema
- * content:
- * application/json:
- * schema:
- * $ref: '#/components/schemas/User'
+ * paths:
+ * /users/create:
+ * post:
+ * summary: Create a new user
+ * description: Creates a new user with the given details.
+ * requestBody:
+ * required: true
+ * content:
+ * application/json:
+ * schema:
+ * $ref: '#/components/schemas/User'
+ * responses:
+ * 200:
+ * description: User created successfully.
+ * 400:
+ * description: Bad request.
+ *
+ * /users:
+ * get:
+ * summary: Get all users
+ * description: Retrieves a list of all users.
+ * responses:
+ * 200:
+ * description: A list of users.
+ * content:
+ * application/json:
+ * schema:
+ * type: array
+ * items:
+ * $ref: '#/components/schemas/User'
+ *
+ * /users/select/{id}:
+ * get:
+ * summary: Search for a user by ID
+ * description: Returns a single user matching the provided ID.
+ * parameters:
+ * - in: path
+ * name: id
+ * required: true
+ * description: Unique ID of the user to retrieve.
+ * schema:
+ * type: string
+ * responses:
+ * 200:
+ * description: A user object.
+ * content:
+ * application/json:
+ * schema:
+ * $ref: '#/components/schemas/User'
+ * 404:
+ * description: User not found.
+ * components:
+ * schemas:
+ * User:
+ * type: object
+ * required:
+ * - username
+ * - email
+ * - password
+ * properties:
+ * username:
+ * type: string
+ * email:
+ * type: string
+ * format: email
+ * description: Email for the user, needs to be unique.
+ * password:
+ * type: string
+ * photo:
+ * type: string
+ * description: Image URL string
+ * nickname:
+ * type: string
+ * example:
+ * username: Renan
+ * email: fake@email.com
+ * password: 123456aa
+ * nickname: Dexter
+ * photo: https://photourl.com/image.png
*/
module.exports = (src) => {
const { UserController } = src.app.Controllers;
+ src.post("/users/create", UserController.createUser);
src.get("/users", UserController.getAllUsers);
-
src.get("/users/select/:id", UserController.searchUserById);
};
diff --git a/swagger.json b/swagger.json
index 8bd43e0..0e07fc4 100644
--- a/swagger.json
+++ b/swagger.json
@@ -20,9 +20,17 @@
"url": "http://localhost:8080"
},
{
- "url": "https://rest-api-node.herokuapp.com"
+ "url": "https://rest-api-node-413916.uc.r.appspot.com"
}
]
},
- "apis": ["./src/app/Models/User.js", "./src/routes/user.js"]
+ "apis": [
+ "./src/app/Middleware/AuthMiddleware.js",
+ "./src/app/Models/User.js",
+ "./src/routes/public/user.js",
+ "./src/routes/private/user.js",
+ "./src/app/Models/Project.js",
+ "./src/routes/public/project.js",
+ "./src/routes/private/project.js"
+ ]
}