Project status: in progress 🚧
- Sign up
- Login
- Reset password
- Get informations about the own profile
- Get informations about another user profile by id
- Follow users
- Unfollow users
- Get feed
- Add recipe
- Edit recipe
- Delete recipe
- Delete all recipes by user id
- Search recipe by id
- Delete user (only admin allowed)
🔹 License
This project is about an Application Programming Interface (API) developed to serve a social media, Cookenu, in which users can share relevant informations about food and recipes they had tried. It has all the most common functionalities in social medias.
🔹 Knex.js 🔹 bcryptjs 🔹 cors 🔹 dotenv 🔹 jsonwebtoken 🔹 nodemailer 🔹 uuid
-
Clone this repository in your machine.
-
In your command line, run:
npm install -
The file
.env.sampleis used for setting up all environment variables you'll need, as the informations about your database, a jwt key (any keyword you want), in nodemailer_user comes your email (some email just for testing, preferably) and its password in nodemailer_password, remember to rename this file just as.env(not obligatory, but... you know, keep it simple):DB_HOST = DB_USER = DB_PASSWORD = DB_SCHEMA = JWT_KEY = NODEMAILER_USER = NODEMAILER_PASSWORD = -
The file
tables.sqlhas all tables used in this project if you want to create them easily.CREATE TABLE users ( id VARCHAR(255) PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, role VARCHAR(255) NOT NULL DEFAULT "NORMAL" );CREATE TABLE recipes ( id VARCHAR(255) PRIMARY KEY, title VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, description VARCHAR(255) NOT NULL, user_id VARCHAR(255) NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) );CREATE TABLE followers ( follower_id VARCHAR(255) NOT NULL, followed_id VARCHAR(255) NOT NULL, following_since TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(follower_id, followed_id), FOREIGN KEY (follower_id) REFERENCES users (id), FOREIGN KEY (followed_id) REFERENCES users (id) ); -
All set? Now you can choose a client REST as Postman, Insomnia or you can even test in your code editor - as I do -, in Visual Studio Code you can install an extension called REST Client and use the file
requests.restin this project to test all endpoints. -
Run
npm run startin your command line and go to your client REST to see the magic happening!
☑️ Sign up
Method: POST
Path: /signup
Input
Body
{
"name": "Hulk",
"email": "hulk-smash@avengers.com",
"password": "123456"
}Output
Body
{
"access_token": "access token"
}☑️ Login
Method: POST
Path: /login
Input
Body
{
"email": "hulk-smash@avengers.com",
"password": "123456"
}Output
Body
{
"access_token": "access token"
}☑️ Reset password
Method: POST
Path: /user/password/reset
Input
Body
{
"email": "hulk-smash@avengers.com"
}☑️ Get informations about the own profile
Method: GET
Path: /user/profile
Input
Headers
Authorization: "authentication token"
Output
Body
{
"id": "user id",
"name": "Hulk",
"email": "hulk-smash@avengers.com"
}☑️ Get informations about another user profile by id
Method: GET
Path: /user/:id
Input
Path Param
id: "user id"Headers
Authorization: "authentication token"Output
Body
{
"id": "user id",
"name": "Hulk",
"email": "hulk-smash@avengers.com"
}☑️ Follow users
Method: POST
Path: /user/follow
Input
Headers
Authorization: "authentication token"Body
{
"followed_id": "user id to follow"
}Output
Body
{
"message": "Followed successfully"
}☑️ Unfollow users
Method: POST
Path: /user/unfollow
Input
Headers
Authorization: "authentication token"Body
{
"followed_id": "user id to unfollow"
}Output
Body
{
"message": "Unfollowed successfully"
}☑️ Get feed
Method: GET
Path: /user/feed
Input
Headers
Authorization: "authentication token"Output
Body
{
"recipes": [
{
"id": "id da receita",
"title": "título da receita",
"description": "descrição da receita",
"createdAt": "31/12/2020",
"userId": "id do usuário que criou a receita",
"userName": "nome do usuário que criou a receita"
}
]
}☑️ Add recipe
Method: POST
Path: /recipe
Input
Headers
Authorization: "authentication token"Body
{
"title": "recipe title",
"description": "recipe description"
}Output
Body
{
"message": "Recipe added successfully!"
}☑️ Edit recipe
Method: POST
Path: /recipe/edit/:id
Input
Path Param
id: "recipe id"Headers
Authorization: "authentication token"Body
{
"title": "new recipe title",
"description": "new recipe description"
}Output
Body
{
"message": "Recipe edited successfully!"
}☑️ Delete recipe
Method: DELETE
Path: /recipe/delete/:id
Input
Path Param
id: "recipe id"Headers
Authorization: "authentication token"Output
Body
{
"message": "Recipe deleted successfully!"
}☑️ Delete all recipes by user id
Method: DELETE
Path: /recipes/delete/all/user/:id
Input
Path Param
id: "user id"Headers
Authorization: "authentication token"Output
Body
{
"message": "All recipes deleted successfully!"
}☑️ Search recipe by id
Method: GET
Path: /recipe/:id
Input
Path Param
id: "recipe id"Headers
Authorization: "authentication token"Output
Body
{
"id": "recipe id",
"title": "Smash soup by Hulk",
"description": "Smaaaaaash",
"cratedAt": "13/06/2021"
}☑️ Delete user (only admin allowed)
Method: DELETE
Path: /admin/delete/user/:id
Input
Path Param
id: "user id"Headers
Authorization: "authentication token"Body
{
"message": "User deleted successfully!"
}|
Alexandra Alcantara ❄️⛄❄️ |
The MIT License (MIT)
Copyright ©️ 2021 - Cookenu