Raman077 / movie-rental

4all backend test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Movie Rental


Usage

With npm installed, run

$ npm install

Make sure that you have docker and docker-compose properly installed.

$ cd docker-database && docker-compose up -d

Start the application by running

$ npm start

Server is running at http://127.0.0.1:3000

REST Routes

  • Basic Auth

Here is an example of what the request Auth heder might look like: Authorization: Basic dGVzdGluZw==

  • Client Creation
POST: http://localhost:3000/4all/movie-rental/client

Body:

{
    "name": "Rafael Silveira",
    "email": "me@rsilveira.dev",
    "pass": "testing"
}

Response

{
    "id": 27,
    "name": "Rafael Silveira",
    "email": "rsilveiracc2@gmail.com",
    "pass": "testing",
    "createdAt": "2019-04-23T00:50:21.405Z"
}
  • Client Update
PUT: http://localhost:3000/4all/movie-rental/client/{CLIENT_ID}

Body:

{
    "name": "Rafael Oliveira",
    "email": "me@rsilveira.dev",
    "pass": "testing"
}

Response

{
    "id": 27,
    "name": "Rafael Oliveira",
    "email": "rsilveiracc2@gmail.com",
    "pass": "testing",
    "createdAt": "2019-04-23T00:50:21.405Z"
}
  • Client Detail
GET: http://localhost:3000/4all/movie-rental/client/{CLIENT_ID}
  • Client Delete
DEL: http://localhost:3000/4all/movie-rental/client/{CLIENT_ID}
  • Client List
GET: http://localhost:3000/4all/movie-rental/clients

Response

[
    {
      "id": 27,
      "name": "Rafael Oliveira",
      "email": "rsilveiracc2@gmail.com",
      "createdAt": "2019-04-23T00:50:21.405Z"
    },
    {
      "id": 28,
      "name": "Rodrigo Cardoso",
      "email": "rodrogio@gmail.com",
      "createdAt": "2019-04-23T00:50:21.405Z"
    }
]
  • Movie Create
POST: http://localhost:3000/4all/movie-rental/movie

Body:

{
    "title": "The Avengers: Endgame",
    "director": "Kevin Feige"
}

Response

{
    "id": 2,
    "title": "The Avengers: Endgame",
    "director": "Kevin Feige"
    "createdAt": "2019-04-23T00:50:21.405Z"
}
  • Movie Update
PUT: http://localhost:3000/4all/movie-rental/movie/{MOVIE_ID}

Body:

{
    "title": "The Avengers: Age of Ultron",
    "director": "Kevin"
}

Response

{
    "id": 2,
    "title": "The Avengers: Age of Ultron",
    "director": "Kevin"
    "createdAt": "2019-04-23T00:50:21.405Z"
}
  • Movie Detail
GET: http://localhost:3000/4all/movie-rental/movie/{MOVIE_ID}

Response

{
    "id": 2,
    "title": "The Avengers: Age of Ultron",
    "director": "Kevin"
    "createdAt": "2019-04-23T00:50:21.405Z"
}
  • Movie Delete
DEL: http://localhost:3000/4all/movie-rental/movie/{MOVIE_ID}
  • Movie Search
GET: http://localhost:3000/4all/movie-rental/movies?title=avengers

Response

[
    {
        "id": 2,
        "title": "The Avengers: Age of Ultron",
        "director": "Kevin"
        "createdAt": "2019-04-23T00:50:21.405Z"
    },
    {
          "id": 3,
          "title": "The Avengers: Endgame",
          "director": "Kevin Feige"
          "createdAt": "2019-04-23T00:50:21.405Z"
    }
]

Response

[
    {
      "id": 2,
      "title": "The Avengers: Age of Ultron",
      "director": "Kevin"
      "createdAt": "2019-04-23T00:50:21.405Z"
    },
    {
      "id": 3,
      "title": "The Avengers: Endgame",
      "director": "Kevin"
      "createdAt": "2019-04-23T00:50:21.405Z"
    }
]
  • Movie Copy Create
POST: http://localhost:3000/4all/movie-rental/movie-copy

Body:

{
    "movieID": 2
}

Response

{
    "id": 1,
    "movieID": 2
    "status": "AVAILABLE"
}
  • Movie Copy Update
PUT: http://localhost:3000/4all/movie-rental/movie-copy/{MOVIE_COPY_ID}

Body:

{
    "movieID": 2
    "status": "RENTED"
}

Response

{
    "id": 2,
    "movieID": 2,
    "status": "RENTED"
}
  • Movie Copy Detail
GET: http://localhost:3000/4all/movie-rental/movie-copy/{MOVIE_COPY_ID}

Response

{
    "id": 2,
    "title": "The Avengers: Age of Ultron",
    "director": "Kevin"
    "createdAt": "2019-04-23T00:50:21.405Z"
}
  • Movie Copy Delete
DEL: http://localhost:3000/4all/movie-rental/movie-copy/{MOVIE_COPY_ID}
  • Rent Create
POST: http://localhost:3000/4all/movie-rental/rent

Body:

{
    "status": "RENTED",
    "clientId": 1,
    "movieCopyId": 2
}

Response

{
    "id": 1,
    "status": "RENTED",
    "clientId": 1,
    "movieCopyId": 2,
    "rentDate": "2019-04-23T00:50:21.405Z"
}
  • Rent Update
PUT: http://localhost:3000/4all/movie-rental/rent/{RENT_ID}

Body:

{
    "movieID": 2
    "clientId": 1,
    "status": "AVAILABLE"
}

Response

{
    "id": 2,
    "movieID": 2,
    "clientId": 1,
    "status": "AVAILABLE"
}
  • Rent Detail
GET: http://localhost:3000/4all/movie-rental/rent/{RENT_ID}

Response

{
    "id": 2,
    "movieID": 2,
    "clientId": 1,
    "status": "AVAILABLE"
}
  • Rent List
GET: http://localhost:3000/4all/movie-rental/rents

Response

[
    {
      "id": 2,
      "movieID": 2,
      "clientId": 1,
      "status": "AVAILABLE"
    },
    {
      "id": 3,
      "movieID": 2,
      "clientId": 3,
      "status": "RENTED"
    }
]

Tests

Run npm test from the root folder.

About

4all backend test


Languages

Language:TypeScript 75.2%Language:TSQL 18.0%Language:HTML 3.3%Language:Dockerfile 1.9%Language:JavaScript 1.7%