Skip to content

alexa2me/express-cookenu-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cookenu

Project status: in progress 🚧

Table of Contents

🔹 What is this project about?

🔹 Requirements

🔹 How to run the application

🔹 Endpoints

  • 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

📃 What is this project about?

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.

🛠️ Requirements

Runtime environment

🔹 NodeJS

Language

🔹 Typescript

Database Service (you can use another one)

🔹 MySQL

Framework

🔹 Express.js

Libraries

🔹 Knex.js 🔹 bcryptjs 🔹 cors 🔹 dotenv 🔹 jsonwebtoken 🔹 nodemailer 🔹 uuid

▶️ How to run the application

  1. Clone this repository in your machine.

  2. In your command line, run:

    npm install

  3. The file .env.sample is 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 =
    
  4. The file tables.sql has 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)
    );
    
  5. 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.rest in this project to test all endpoints.

  6. Run npm run start in your command line and go to your client REST to see the magic happening!

🚩 Endpoints

🤘 Users

☑️ 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"
}

🍰 Recipes

☑️ 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"
}

🔐 Admin

☑️ 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!"
}

🚀 Developer :octocat:

Imagem do perfil da Alexandra
Alexandra Alcantara
❄️⛄❄️

License

The MIT License (MIT)

Copyright ©️ 2021 - Cookenu

About

An API developed for an imaginary social media called Cookenu in which users can share their favorite recipes.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors