Coder Social home page Coder Social logo

biorubenfs / blockbuster_2.0 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.69 MB

New version of API REST blockbuster, made with nodejs, express and mongo as database. It follow MVC pattern and it has basic CRUD operations. It also uses JWT for authentication.

Shell 0.73% JavaScript 98.29% HTML 0.98%
nodejs express crud mvc mocha-chai mongodb mongoose swagger supertest jwt-token api-rest ajv

blockbuster_2.0's Introduction

Blockbuster 2.0

Videoclub API REST using nodejs, express, mongoose and mongodb. It has been built using MVC pattern. Basic CRUD operations are implemented. This project was developed during my fullstack bootcamp and improved after its ending.

Table of contents

  1. Introduction
  2. Setup
  3. Main Endpoints
  4. Documentation
  5. Testing
  6. Tools

1. Introduction

This is a basic API REST project. Users can signup and rent movies placing an order. The catalogue is available for everybody without registration. Several actions can be perfomed only by admins.

2. Setup

2.1 Dependencies

Download or clone de the repository. After that, run:

npm install

2.2 Database configuration

Database configuration is in config/db_connection.js file. Change as many parameters as necessary.

2.3 Seeders

After dependencies has been installed, run the seeds as follows:

npm run seed

3. Main Endpoints

Authentication

Authentication 🔑

Some blockbuster endpoints can be used without registration or token.

How to register? POST /signup

/signup endpoint allows users to signup in tha pp. After this process, users will be able to get a token through signin endpoints (see below). To register, user should include in body request an email, an username and a password. Password will be stored hashed.

{
  "username": "documentation",
  "email": "[email protected]",
  "password": "1234"
}

Getting a token. POST /signin

After registration, user will be able to login and obtain a token. This token is valid to make orders and update user profile.

{
  "email": "[email protected]",
  "password": "1234"
}

This endpoints returns a token:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxMDZhYjY2NTQ4OWFkMWMxM2NmMzAyNCIsImVtYWlsIjoiZG9jdW1lbnRhdGlvbkBibG9ja2J1c3Rlci5jb20iLCJyb2xlIjoiVVNFUiIsImlhdCI6MTYyNzgyOTkwNn0.YaKnKIm6Ux76CjXIY1JjyaCs_Doa2MEQeTxmZ0u600Y"
}
Users

Users

GET /users/me

It returns a JSON object with user details available in database. Token is mandatory. In Postman select Auth > Bearer Token and add the token you obtained in your login.

{
  "role": "USER",
  "_id": "6106ab665489ad1c13cf3024",
  "username": "documentation",
  "email": "[email protected]"
}

DELETE /users/me

Users can delete their account. Only the token is necessary for this purpose.

PUT /users/me

Users can update their account details, including their profile picture. To do that in Postman, select form-data type in body. Users can update their profile picture, their username and password.

key type value
profile_picture file image.jpg
username text newUsername
password text newPassowrd

This endpoint returns something like this:

{
  "role": "USER",
  "_id": "6106ab665489ad1c13cf3024",
  "username": "new username",
  "email": "[email protected]",
  "password": "$2b$10$UXbEvFkghb44mlinYSyoDe0EbROsezUnGpxR2QoyvX2dYJlDuhUF2",
  "profile_picture": "assets/profile_pictures/1627831302408image.jpeg"
}

and stores the profile picture in ./assets/profile_pictures.

Movies

Movies

All these endpoints can be used without token.

GET /movies

It returns the complete list of movies available in database.

[
    {
        "cast": [
            "Tim Robbins",
            "Morgan Freeman",
            "Bob Gunton",
            "William Sadler",
            "Clancy Brown",
            "Gil Bellows",
            "Mark Rolston",
            "James Whitmore",
            "Jeffrey DeMunn",
            "Larry Brandenburg"
        ],
        "genres_ids": [
            18,
            80
        ],
        "_id": "6105cb21ead58228b7e30a87",
        "title": "Cadena perpetua",
        "year": "1994",
        "poster_path": "https://image.tmdb.org/t/p/w500/dc1fX265fZIIY5Hab8I7CdETyJy.jpg",
        "overview": "Acusado del asesinato de su mujer, Andrew Dufresne, tras ser condenado a cadena perpetua, es enviado a la prisión de Shawshank. Con el paso de los años conseguirá ganarse la confianza del director del centro y el respeto de sus compañeros presidiarios, especialmente de Red, el jefe de la mafia de los sobornos."
    },
    {},

GET /movies/[id]

It returns details about a specific movie:

For example: /movies/6105cb22ead58228b7e30a90

{
  "cast": [
    "Marlon Brando",
    "Al Pacino",
    "James Caan",
    "Robert Duvall",
    "Richard S. Castellano",
    "Diane Keaton",
    "Talia Shire",
    "Gianni Russo",
    "Sterling Hayden",
    "Al Lettieri"
  ],
  "genres_ids": [18, 80],
  "_id": "6105cb22ead58228b7e30a90",
  "title": "El padrino",
  "year": "1972",
  "poster_path": "https://image.tmdb.org/t/p/w500/wLXd1Cd0XW7DhXayfC0Ok5ago9r.jpg",
  "overview": "Don Vito Corleone, conocido dentro de los círculos del hampa como 'El Padrino', es el patriarca de una de las cinco familias que ejercen el mando de la Cosa Nostra en Nueva York en los años ccuarenta. Don Corleone tiene cuatro hijos: una chica, Connie, y tres varones; Sonny, Michael y Fredo. Cuando el Padrino reclina intervenir en el negocio de estupefacientes, empieza una cruenta lucha de violentos episodios entre las distintas familias del crimen organizado."
}

GET /movies/search/title

It allows the user to do a search by titles based on a query term.

For example: /movies/search/title?title=padrino

GET /movies/search/genre_id/[genreId]

It returns a list of a genre. Beware not to use the mongo objectId _id. Instead of that use the id. This is because of movies and relative data were obtained from moviedb database. Check genre collection if you have doubts.

GET /movies/search/genre_name/[genreName]

Very similar to the previous one, but using the genre name instead of id.

Orders

Orders

POST /orders/

Users can do orders through this endpoints. Just a movieId is necessary.

{
  "movieId": "60f85d56826def399ee61525"
}

It returns order information:

{
  "status": "ACTIVE",
  "_id": "6106ca5a506e763441dc9ced",
  "movie_id": "60f85d56826def399ee61525",
  "user_id": "6106ab665489ad1c13cf3024",
  "start_date": "2021-08-01T16:22:50.029Z",
  "end_date": "2021-08-11T16:22:50.029Z"
}

GET /orders/

This endpoints returns all order from token user:

[
  {
    "status": "ACTIVE",
    "user_id": "6105cb21666f5a28a70c7ea4",
    "movie_id": {
      "_id": "6105cb21ead58228b7e30a87",
      "title": "Cadena perpetua"
    },
    "start_date": "2021-07-31T22:13:55.149Z",
    "end_date": "2021-07-31T22:13:55.149Z"
  },
  {
    "status": "ACTIVE",
    "user_id": "6105cb21666f5a28a70c7ea4",
    "movie_id": {
      "_id": "6105cb22ead58228b7e30a92",
      "title": "La lista de Schindler"
    },
    "start_date": "2021-07-31T22:13:55.152Z",
    "end_date": "2021-07-31T22:13:55.152Z"
  }
]

GET /orders/:id

PUT /orders/:id

Admin

Title

Explanation text

4. Documentation 📔

5. Testing

6. Tools 🔩

6.1 Main libraries

6.2 Main tools

Author 🏀

Rubén Fernández Santos

blockbuster_2.0's People

Contributors

biorubenfs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.