Challenge 7: Movies Website Backend II: Finder

This project was proposed and deployed on the 5th week of GeeksHubs' Full Stack Developer Bootcamp

Este proyecto se propuso e implementó en la 5ª semana del Bootcamp Full Stack Developer de GeeksHubs

Index

English

Español

English

Goal and used technologies

The aim of the project was to develop an only-backend service for movies rental, with four defined areas:

  • User Management
    • Sign Up Endpoint
    • Profile Endpoint
    • Delete Account Endpoint
    • Log In Endpoint
    • Extra features: JWT; Admin and Client
  • Movie/Product Management
    • Search by Title Endpoint
    • Search by Id Endpoint
    • Display all Movies Endpoint
    • Extra features: Filter by Actress/Actor;
      Filter by Genre
  • Order Management
    • Create an Order Endpoint
      • One Movie per Client
      • Reception and Return Dates
    • Extra features: Show all Orders (as Admin).
  • Data Management
    • Use of an ORM (Sequelize/MongoDB/MySQL)

The technologies we used were:

Visual Studio Code JavaScript Node.js Express.js JWT BCrypt Postman MySQL Workbench Sequelize

Index, routing and middleware

index.js

const express = require('express');
const app = express();
const port = 3006;
const router = require('./router');

app.use(router);
app.use(express.json());

app.listen(port, () => console.log(`Node server running on http://localhost:${port}`));

This js file:

  1. imported the Express.js library,
  2. saved its functionalities on "app",
  3. selected 3006 as the server's port and
  4. linked router.js.

Then, the router.js' and express.json()' functionalities were "used", or, we assume, loaded in memory.

app.listen() started a local node.js server that uses the 3006 port.

router.js

const router = require('express').Router();

const moviesRouter = require('./routes/moviesRouter.js');
const seriesRouter = require('./routes/seriesRouter.js');

router.use('/movies', moviesRouter);
router.use('/series', seriesRouter);


module.exports = router;

This js file imports the .Router() utility from Express.js, which is used to link the moviesRouter, customerRouter, orderRouter and loginRouter paths, and therefore their content, to index.js. In this sense, router.js is merely a link between the main application (index.js) to its dependencies.

Endpoints and DB Management

Prerequisites


Clone the project from here.

Install the needed dependencies (on Bash):

npm i

Install Postman from here.

In Postman:

  1. Add a new collection
  2. Use GET with the address: http://localhost:3006

    Although we used 3006 as the default port, you can use another one of your choice.

Movies:


To search top rated movies type the following:
http://localhost:3006/movies

To find movies by id just add a number after movies: POST
http://localhost:3006/movies

To find movies by title: POST
http://localhost:3006/movies/title

To search movies by genre: POST
http://localhost:3006/movies/genre

To search movies by actor/actress: POST
http://localhost:3006/movies/actor/

Customers


To get the list of all customers: GET
http://localhost:3006/customer

To find a customer by id: POST - {"customerId": "id"}
http://localhost:3006/customer/id

To find a customer by name: POST - {"name": "name"}
http://localhost:3006/customer/name

To create a new customer (this will check first if mail exists in the database): POST
http://localhost:3006/customer

To modify some attributes of the customer: PUT
http://localhost:3006/customer

To delete a customer: DELETE - {"id": "id"}
http://localhost:3006/customer

Login


To log in: POST - {"mail": "yourmail", "password", "yourpassowrd"} http://localhost:3006/login/

Do not forget to save your token to postman Authorization "bearer token", to realize your actions.

Orders


To get the list of all orders: GET
http://localhost:3006/order

To find a order by id: POST - {"id": "id"}
http://localhost:3006/order/id

To find a order by city: POST - {"city": "city"}
http://localhost:3006/order/city

To create a new order: POST
http://localhost:3006/order/

To delete a order: DELETE - {"id": "id"}
http://localhost:3006/order

Series


To obtain a list of top rated series:
http://localhost:3006/series/toprated

To find a tv show by id:
http://localhost:3006/series/id/ (your id)

To find a serie by their title:
http://localhost:3006/series/title/ (your title)

Obtaining series which will have at least one episode aired in the next seven day:
http://localhost:3006/series/ontheair7/

Obtaining series which are screened on theaters:
http://localhost:3006/series/screenedtheater/

Español

Objetivo y tecnologías empleadas

El objetivo del proyecto es desarrollar un servicio (solo la parte backend) para alquiler de películas, con cuatro áreas definidas:

  • Gestión de Usuarios
    • Endpoint para Darse de Alta
    • Endpoint para mostart Información de la Cuenta
    • Endpoint para Darse de Baja
    • Endpoint para Iniciar Sesión
    • Características extra: JWT; Admin y Cliente
  • Gestión de Películas/Productos
    • Endpoint para Búsqueda por Título
    • Endpoint para buscar por Id
    • Endpoint para Mostrar todas las Películas
    • Características extra: Filtrar por Actriz/Actor;
      Filtrar por Género
  • Gestión de los Pedidos
    • Endpoint para Crear un Pedido
      • Una única Película por Cliente
      • Fechas de Recepción y de Devolución
    • Características extra: Mostrar todos los Pedidos (solo para el Admin)
  • Gestión de Datos
    • Emplear un ORM (Sequelize/MongoDB/MySQL)

Las tecnologías empleadas fueron:

Visual Studio Code JavaScript Node.js Express.js JWT BCrypt Postman MySQL Workbench Sequelize

Index, routing y middleware

index.js

const express = require('express');
const app = express();
const port = 3006;
const router = require('./router');

app.use(router);
app.use(express.json());

app.listen(port, () => console.log(`Node server running on http://localhost:${port}`));

Este archivo js:

  1. importó la librería Express.js,
  2. guardó sus herramientas en "app",
  3. seleccionó 3006 como el puerto para el servidor y
  4. linked router.js.
  5. enlazó con router.js

Entonces, las herramientras de router.js y de express.json fueron "usadas", o, asumimos, guardadas en memoria.

app.listen() lanzó un servidor local node.js que emplea el puerto 3006.

router.js

const router = require('express').Router();

const moviesRouter = require('./routes/moviesRouter.js');
const seriesRouter = require('./routes/seriesRouter.js');

router.use('/movies', moviesRouter);
router.use('/series', seriesRouter);


module.exports = router;

Este archivo js importa la herramienta .Router() desde Express.js, la cual emplea para enlazar las rutas de moviesRouter, loginRouter, orderRouter y customerRouter, y por tanto su contenido, con index.js. En este sentido, router.js es un mero enlace entre la aplicación principal (index.js) con sus dependencias.


Gestión de los Endpoints y la base de datos

Prerequisitos


Clonar el proyecto desde aquí.

Instalar dependencias (desde Bash):

 npm i

Instalar Postman desde aquí.

En Postman:

  1. Crea una nueva colección
  2. Emplea GET con la dirección: http://localhost:3006

    Aunque nosotros hemos usado el puerto 3006, se puede utilizar cualquier otro a voluntad.

Movies:


Búsqueda de películas mejor valoradas

http://localhost:3006/movies

Búsqueda de películas por id POST
http://localhost:3006/movies

Búsqueda de películas por título POST
http://localhost:3006/movies/title

Búsqueda de películas por género POST
http://localhost:3006/movies/genre

Búsqueda de películas por actor/actriz POST
http://localhost:3006/movies/actor/

Customers


Obtener una lista de todos los clientes GET

http://localhost:3006/customer

Búsqueda de cliente por id POST - {"customerId": "id"}
http://localhost:3006/customer/id

Búsqueda de cliente por nombre POST - {"name": "name"}
http://localhost:3006/customer/name

Crear un nuevo usuario (comprobará primero si el email ya está registrado) POST
http://localhost:3006/customer

Modificar datos del cliente PUT
http://localhost:3006/customer

Eliminar cliente DELETE - {"id": "id"}
http://localhost:3006/customer

Login


Login POST - {"mail": "yourmail", "password", "yourpassowrd"} http://localhost:3006/login/

No olvidar almacenar el token en Authorization/Bearer Token!

Orders


Listar todos los pedidos GET

http://localhost:3006/order

Búsqueda de pedido por id POST - {"id": "id"}
http://localhost:3006/order/id

Búsqueda de pedido por ciudad POST - {"city": "city"}
http://localhost:3006/order/city

Crear nuevo pedido POST
http://localhost:3006/order/

Borrar pedido DELETE - {"id": "id"}
http://localhost:3006/order

Series


Listar series mejor valoradas

http://localhost:3006/series/toprated

Búsqueda de series por id
http://localhost:3006/series/id/ (your id)

Búsqueda de series por título
http://localhost:3006/series/title/ (your title)

Listar series que serán emitidas en los próximos siete días
http://localhost:3006/series/ontheair7/

Listar series que serán representadas en cines o teatros
http://localhost:3006/series/screenedtheater/

Conclusiones