Introducing Jukebox, a digital music service where users can curate playlists of tracks to best match their mood!
See DBML
table playlists {
id serial [pk]
name text [not null]
description text [not null]
}
table playlists_tracks {
id serial [pk]
playlist_id integer [not null]
track_id integer [not null]
indexes {
(playlist_id, track_id) [unique]
}
}
table tracks {
id serial [pk]
name text [not null]
duration_ms integer [not null]
}
Ref: playlists.id < playlists_tracks.playlist_id
Ref: tracks.id < playlists_tracks.track_id
There is a many-many relationship between playlists and tracks. If a junction table exists purely to implement the many-many relationship, the convention is simply to combine the names of the two linked tables.
- Create a new database named
jukebox. - Write
db/schema.sqlto create tables according to the schema above.- If either a playlist or a track is deleted, the deletion should cascade to all related playlists_tracks records.
- Each track can only be in a playlist once. (Use a unique constraint!)
- Complete
seed.jsand necessary queries to seed the database with at least 20 tracks and 10 playlists. Create at least 15 playlists_tracks so that some of the seeded tracks belong to some of the seeded playlists.
Once your database is properly seeded, build an Express app that serves the following
endpoints. Remember to send appropriate status codes and error messages! You can use npm run test to check your work as you build out these endpoints.
/tracks router
GET /trackssends array of all tracksGET /tracks/:idsends track specified by id
/playlists router
GET /playlistssends array of all playlistsPOST /playlistscreates a new empty playlistGET /playlists/:idsends playlist specified by idGET /playlists/:id/trackssends all tracks in the playlistPOST /playlists/:id/tracksadds a new track to the playlisttrackIdshould be sent in request body- Sends the created
playlist_trackwith status 201