Skip to content

PerryBaran/book-library

Repository files navigation

Book-Library

An Express.js API that interacts with a sequelize database via CRUD requests to store and interact with reader and book information.

Sequelize uses MySQL dialect for tests and Postgres for production.

Implements Test-Driven development using Mocha and Chai.

Created as part of the Manchester Codes full-stack web development boot-camp.

App hosted on Render at https://book-library-f9gi.onrender.com.

Table of Contents

  1. Dependencies
  2. Setup
  3. Commands
  4. Routes
  5. Attribution

Dependencies

Dev Dependencies

Setup

Install Dependencies

$ npm i

Database

If you have Docker installed, To set the database up, pull and run a MySQL image with:

$ docker run -d -p 3307:3306 --name book_library_mysql -e MYSQL_ROOT_PASSWORD=password mysql

Environment variables

You will need to create a file to store your environment variables. These credentials allow you to connect to the database. Two environments will need to be created, one for production and one for testing.

Create a .env file in the root of the repo with the following values:

DB_PASSWORD=password
DB_NAME=book_library
DB_USER=root
DB_HOST=localhost
DB_PORT=3307

Create a .env.test file in the root of the repo with the following values:

DB_PASSWORD=password
DB_NAME=book_library_dev
DB_USER=root
DB_HOST=localhost
DB_PORT=3307

Commands

To run the server use:

$ npm start

To run all tests use:

$ npm test

To only run unit tests use:

$ npm run unit-test

To run Prettier use:

$ npm run prettier

Routes

? In Schema represents optional field

/readers

Method Route Description Schema (JSON)
POST /readers Creates new reader
{
"name": STRING,
"email": STRING,
"password": STRING
}
GET /readers Returns all readers N/A
GET /readers/{readerId} Returns reader of specified ID N/A
PATCH /readers/{readerId} Updates reader with specified ID
{
"name"?: STRING,
"email"?: STRING,
"password"?: STRING
}
DELETE /readers/{readerId} Deletes reader with specified ID N/A

/books

Method Route Description Schema (JSON)
POST /books Creates new book
{
"title": STRING,
"ISBN"?: STRING,
"authorId": INTEGER,
"genreId"?: INTEGER
}
GET /books Returns all books and associated genres and authors N/A
GET /books/{bookId} Returns book of specified ID and associated genre and author N/A
PATCH /books/{bookId} Updates book with specified ID
{
"title"?: STRING,
"ISBN"?: STRING,
"authorId"?: INTEGER,
"genreId"?: INTEGER
}
DELETE /books/{bookId} Deletes book with specified ID N/A

/authors

Method Route Description Schema (JSON)
POST /authors Creates new author
{
"author": STRING
}
GET /authors Returns all authors and associated books and genres N/A
GET /authors/{authorId} Returns author of specified ID and associated books and genres N/A
PATCH /authors/{authorId} Updates author with specified ID
{
"author": STRING
}
DELETE /authors/{authorId} Deletes author with specified ID N/A

/genres

Method Route Description Schema (JSON)
POST /genres Creates new genre
{
"genre": STRING
}
GET /genres Returns all genres and associated books and authors N/A
GET /genres/{genreId} Returns genre of specified ID and associated books and authors N/A
PATCH /genres/{genreId} Updates genre with specified ID
{
"genre": STRING
}
DELETE /genres/{genreId} Deletes genre with specified ID N/A

Attribution

Created by Perry Baran.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published