Skip to content

API school project written in NodeJS with Yarn. Keep track of your favourite beers, give them a rating and add a description!

Notifications You must be signed in to change notification settings

JentlSuy/webservices-pieter-2122-JentlSuyBeerReviewAPI

Repository files navigation

webservices-pieter-2122-JentlSuy

BeerReview API - Jentl Suy

School result: 17/20

The idea

The api provides a list of beers along with their breweries. The idea is that users can review their favorite beer by giving them a rating.

What the data looks like

  • A review is created by a user and contains a rating (0-5) of a beer, a description explaining the review, a date and the beer_id of the beer that is reviewed.
  • A user has a name, an email, a hashed password and a role (USER or ADMIN).
  • A beer contains a name, the brewery_id (where the beer is brewed), and the alcohol percentage (0% - 100%).
  • A brewery has a name and country of where the brewery is located.
reviews users beers breweries
id : CHAR id : CHAR id : CHAR id : CHAR
rating : INT name : VARCHAR name : VARCHAR name : VARCHAR
description : VARCHAR email : VARCHAR brewery_id : CHAR country : VARCHAR
date : DATETIME password_hash : VARCHAR percentage : DOUBLE
user_id : CHAR roles : JSON
beer_id : CHAR
Example data in MySQL:
select re.id as review_id, be.name as beer, br.name as brewery, rating, description, us.name as user, re.date from reviews re
join beers be on be.id = re.beer_id
join users us on us.id = re.user_id
join breweries br on br.id = be.brewery_id;

image

Hosted onine

The API is hosted online and is accessible via https://jentlsuy-beerreview-api.herokuapp.com/swagger or via Postman.

How to start locally

  1. Have MySQL server installed: https://dev.mysql.com/downloads/mysql/.
  2. Run a local MySQL server instance
  3. Have NodeJS installed: https://nodejs.org/en/
  4. Have yarn installed: https://classic.yarnpkg.com/lang/en/docs/install/
  5. Check the .env file in the root of this folder.
NODE_ENV="development"
DATABASE_USERNAME="root"
DATABASE_PASSWORD="root"

Update the username and password with the credentials of your local MySQL server database.

  1. Run the following command on the root folder of this project in a terminal window or in Visual Studio Code:
yarn start

Error? Check the 'Common errors' section below.

How to test

Test the app with yarn test. Note that the app is tested with the --runInBand CLI flag to prevent Jest from testing in parallel. You can change this in the package.json.

Swagger

Note that Swagger is included with this API. To use Swagger, simply go to http://localhost:9000/swagger to view all the existing API-calls or go to https://jentlsuy-beerreview-api.herokuapp.com/swagger to access the hosted version.

How to log-in

Every API-call in this application requires authentication. Use the login call in Swagger or go to http://localhost:9000/api/users/login in Postman.

In order to login, you will need an email and password. You can create a new account using the register call or use the credentials below to login to an existing account:

ADMIN:

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

USER:

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

You will receive a token as a response. Use this token as a bearerAuthentication-token to get access to every other api-call in this application.

Note: only an ADMIN can access the user-related API-calls.

Print-out of the Swagger API

image

About the test-files

There are currently 2 objects (reviews & beers) tested in the rest-folder. Every existing call that is used with these 2 objects is tested, resulting in a total of 11 test-methods. The coverage of these tests are above 80 % as you can see in the screenshot below:

image

Common errors

  • Modules not found errors, try this and run again:
yarn install
  • Migrations failed, try dropping the existing beerreview database and run again.

About

API school project written in NodeJS with Yarn. Keep track of your favourite beers, give them a rating and add a description!

Topics

Resources

Stars

Watchers

Forks

Languages