In the initial commit of this project you were provided with data on several novels including their author and genres. Working in a branch called part-one-answer
, your tasks are:
- Design a normalized table structure to hold this data
- Create the SQL to build that database with its user and tables and insert all of the data
- Create an Express driven REST API that allows a user to retrieve the data
Your API should support the routes listed below, pulling the data from the database via Sequelize models.
GET http://localhost:1337/authors
Response
[
{
id: 1,
nameFirst: 'Bram',
nameLast: 'Stoker',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z'
},
{
id: 2,
nameFirst: 'Oscar',
nameLast: 'Wilde',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z'
},
... all other authors
]
GET http://localhost:1337/authors/2
Response
{
id: 2,
nameFirst: 'Oscar',
nameLast: 'Wilde',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z',
novels: [
{
id: 2,
title: 'The Picture of Dorian Gray',
authorId: 2,
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z',
genres: [
{
id: 6,
name: 'Fantasy',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z',
novelsGenres: {
genreId: 6,
novelId: 2,
createdAt: '2020-04-04T15:58:00.000Z',
updatedAt: '2020-04-04T15:58:00.000Z'
}
},
... all other genres for novel
]
},
... all other novels by author
]
}
GET http://localhost:1337/genres
Response
[
{
id: 1,
name: 'Adventure',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z'
},
{
id: 2,
name: 'African Literature',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z'
},
... all other genres
]
GET http://localhost:1337/genres/2
Response
{
id: 2,
name: 'African Literature',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z',
novels: [
{
id: 15,
title: 'Things Fall Apart',
authorId: 15,
createdAt: '2020-04-04T15:58:00.000Z',
updatedAt: '2020-04-04T15:58:00.000Z',
novelsGenres: {
genreId: 2,
novelId: 15,
createdAt: '2020-04-04T15:58:01.000Z',
updatedAt: '2020-04-04T15:58:01.000Z'
},
author: {
id: 15,
nameFirst: 'Chinua',
nameLast: 'Achebe',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z'
}
}
]
}
GET http://localhost:1337/novels
Response
[
{
id: 1,
title: 'Dracula',
authorId: 1,
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z',
author: {
id: 1,
nameFirst: 'Bram',
nameLast: 'Stoker',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z'
},
genres: [
{
id: 6,
name: 'Fantasy',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z',
novelsGenres: {
genreId: 6,
novelId: 1,
createdAt: '2020-04-04T15:58:00.000Z',
updatedAt: '2020-04-04T15:58:00.000Z'
}
},
... all other genres for novel
]
},
... all other novels
]
GET http://localhost:1337/novels/4
Response
{
id: 4,
title: 'War and Peace',
authorId: 4,
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z',
author: {
id: 4,
nameFirst: 'Leo',
nameLast: 'Tolstoy',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z'
},
genres: [
{
id: 7,
name: 'Fiction',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z',
novelsGenres: {
genreId: 7,
novelId: 4,
createdAt: '2020-04-04T15:58:00.000Z',
updatedAt: '2020-04-04T15:58:00.000Z'
}
},
... all other genres for novel
]
}
In a branch called part-two-answer
, continuing from your previous work, your tasks are:
- Create a Sequelize Migration to create your table structure in the database (you'll need to drop and recreate your existing database to clear it out)
- Create a Sequelize Migration that will populate your database with all the data
- Create a .env and .env-sample file to support your dynamic configuration
- Update your API to support the new routes listed below, all existing routes should continue to work
GET http://localhost:1337/authors/wild
Response
{
id: 2,
nameFirst: 'Oscar',
nameLast: 'Wilde',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z',
novels: [
{
id: 2,
title: 'The Picture of Dorian Gray',
authorId: 2,
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z',
genres: [
{
id: 6,
name: 'Fantasy',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z',
novelsGenres: {
genreId: 6,
novelId: 2,
createdAt: '2020-04-04T15:58:00.000Z',
updatedAt: '2020-04-04T15:58:00.000Z'
}
},
... all other genres for novel
]
},
... all other novels by author
]
}
GET http://localhost:1337/novels/peace
Response
{
id: 4,
title: 'War and Peace',
authorId: 4,
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z',
author: {
id: 4,
nameFirst: 'Leo',
nameLast: 'Tolstoy',
createdAt: '2020-04-04T15:57:59.000Z',
updatedAt: '2020-04-04T15:57:59.000Z'
},
genres: [
{
id: 7,
name: 'Fiction',
createdAt: '2020-04-04T15:57:58.000Z',
updatedAt: '2020-04-04T15:57:58.000Z',
novelsGenres: {
genreId: 7,
novelId: 4,
createdAt: '2020-04-04T15:58:00.000Z',
updatedAt: '2020-04-04T15:58:00.000Z'
}
},
... all other genres for novel
]
}