This is the title service for audibles.com. This services displays the title, book information, image, audio sample, and dynamic background image. This service is apart of a larger group project with an emphasis on service oriented architecture. you can learn more about the project here
- React
- Node with Express
- MySQL
- AWS S3
- AWS EC2
- Lighthouse
- Jest
- Enzyme
- Puppeteer
- dynamic background Image
- image stretched, blurred, and darkened using only css
- audio sample
- lazy loads on user click
- dynamic countdown timer
- Lighthouse page load speed of 100
An nvmrc
file is included if using nvm.
- Node 12.22.1
- From within the root directory:
npm install
- create a .env file containing the following:
DB_USER={mysqlUserName}
DB_PASSWORD={mysqlPassword}
DB_HOST={mysqlHost}
-
create a new PostgreSQL database named:
audible
-
seed the database with:
npm run seed-postgres
-
build the client bundle with:
npm run react-dev
-
start the server with:
npm run server-dev
1a. Install couchimport:
npm install -g couchimport
- create a .env file containing the following:
DB_LOGIN_URL='http://admin:{password}@127.0.0.1:5984'
-
create a new PostgreSQL database named:
audible
-
seed the database with:
npm run seed-postgres
-
build the client bundle with:
npm run react-dev
-
start the server with:
npm run server-dev
Seed the database by running
npm run seed-db
this will populate three tables
- Books
- Categories
- Book_Category
- this table is a join table for the many to many relationship between Books and Categories
MODELS:
Book.js contains several methods:
- getById - takes in a single ID and returns a single book including the category through sequelize eager loading
- getByIds - takes in an array of IDs and returns an array of book objects including category through sequelize eager loading
- getRelatedById - takes in an id and returns an object containing
{byAuthor: [], byNarrator: []}
this method will not include the original input book in either list
it will also not include books by the original book's author in the byNarrator list
GET:
- /api/book/{id}
- returns a single book
- /api/books
- takes in json 'ids' - an array of ids OR a query param 'ids' equal to a comma separated list of ids
- returns an array of book objects
- /api/book/{id}/related
- returns an object containing related books
- {byAuthor: [], byNarrator:[]}
POST:
- /api/book
- takes a 'book' parameter with the following properties
book: { title: 'string', // Required subtitle: 'string', author: 'string', // Required narrator: 'string', // Required imageUrl: 'string', audioSampleUrl: 'string', length: 'string', version: 'string', createdAt: 'datetime', updatedAt: 'datetime };
PUT:
- /api/book/:id
- takes id as last url parameter
- takes a 'book' parameter (above) with the properties to be updated.
- updates all given parameters
DELETE:
- /api/book/:id
- takes id as last url parameter
- delete's specified book from the database
WARNING currently running npm run test
will repopulate the database.
see /test/setupDb.js
to disable re-seed for tests