School result: 17/20
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.
- 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 |
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;
The API is hosted online and is accessible via https://jentlsuy-beerreview-api.herokuapp.com/swagger or via Postman.
- Have MySQL server installed: https://dev.mysql.com/downloads/mysql/.
- [Optional] Have MySQL Workbench installed: https://dev.mysql.com/downloads/workbench/
- Run a local MySQL server instance
- Have NodeJS installed: https://nodejs.org/en/
- Have yarn installed: https://classic.yarnpkg.com/lang/en/docs/install/
- 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.
- 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.
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
.
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.
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.
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:
- Modules not found errors, try this and run again:
yarn install
- Migrations failed, try dropping the existing
beerreview
database and run again.