- Introduction
- Initial Setup
- How to Run Tests
- How to Use
- Endpoints
- Schema Design
- Tech Stack List
- Core Contributors
Follow the following steps to setup application locally. Setup time is 5-10 minutes.
The easiest way to get started is to run the following command. This will pull down any necessary dependencies that your app will require.
npm install
You’ll need to figure out a name for your database. We suggest calling it something like play_play_express_dev
.
You will also need to update the development section of the knexfile with the database name.
To get things set up, you’ll need to access your Postgres instance by typing in psql
into your terminal. Once there, you can create your database by running the comment CREATE DATABASE PUT_DATABASE_NAME_HERE_dev;
.
Once you have your database setup, you’ll need to run some migrations (if you have any). You can do this by running the following command:
knex migrate:latest
Instructions to create database, run migrations, and seed:
psql
CREATE DATABASE DATABASE_NAME_dev;
\q
knex migrate:latest
knex seed:run
Enviroment keys are required to use the Google Geocoding and DarkSky Service.
Obtain a Musix Match API key
Create an .env
file in the root of the dictory
In the .env
file, add the following information:
MUSIX_MATCH_API_KEY= your_musix_match_api_key
Add the .env
to your .gitignore to avoid the file being pushed to GitHub
Most of the setup is going to be same as the one you did before. You’ll notice one small difference with setting the environment flag to test
.
psql
CREATE DATABASE DATABASE_NAME_test;
\q
knex migrate:latest --env test
You will also need to update the test section of the knexfile with the test database name.
Running tests are simple and require you to run the following command below:
npm test
We recommend using Postman to hit endpoints.
Production address
https://play-play-express.herokuapp.com/
Local address
http://localhost:3000/
Returns all favorite tracks from the database
GET /api/v1/favorites
If successful, application will respond with status code 200 and JSON with array of tracks.
Sample Successful Response:
[
{
"id": 1,
"title": "Bailamos",
"artistName": "Enrique Iglesias",
"genre": "Pop",
"rating": 88
},
{
"id": 2,
"title": "The Chain",
"artistName": "Fleetwood Mac",
"genre": "Rock",
"rating": 52
}
]
Returns a single favorite track from the database
GET /api/v1/favorites/:id
:id
: id of desired favorite track
If successful, application will respond with status code 200 and JSON of requested track.
Sample Successful Response:
[
{
"id": 2,
"title": "The Chain",
"artistName": "Fleetwood Mac",
"genre": "Rock",
"rating": 52
}
]
Delete a single favorite track from the database
DELETE /api/v1/favorites/:id
:id
: id of the track to be deleted
If successful, application will respond with 201 status.
Add a new favorite track. The track title must be included in the POST request body. Including the track's artist is optional.
POST /api/v1/favorites
title
: title of the desired track
artist
: (optional) artist of the desired track
If successful, application will respond with 201 status and return JSON of newly posted favorite track.
Sample Successful Response:
[
{
"id": 19,
"title": "Stronger",
"artistName": "Kelly Clarkson",
"genre": "Electronic",
"rating": 30
}
]
Returns all playlists from the database
GET /api/v1/playlists
If successful, application will respond with status code 200 and JSON with array of playlists.
Sample Successful Response:
[
{
"id": 1,
"title": "90s Guilty Pleasure",
"songCount": 1,
"songAvgRating": 88,
"favorites": [
{
"id": 1,
"title": "Bailamos",
"artistName": "Enrique Iglesias",
"genre": "Pop",
"rating": 88
}
],
"updated_at": "2019-12-11T19:40:01.088Z",
"created_at": "2019-12-11T19:40:01.088Z"
},
{
"id": 2,
"title": "Party Mix",
"songCount": 0,
"songAvgRating": 0,
"favorites": [],
"updated_at": "2019-12-11T19:40:01.088Z",
"created_at": "2019-12-11T19:40:01.088Z"
}
]
Add a new playlist. A unique playlist title must be included in the POST request body.
POST /api/v1/playlists
title
: title of playlist
If successful, application will respond with 201 status and return JSON of newly posted playlist record.
Sample Successful Response:
[
{
"id": 17,
"title": "Electronic Dance Music Playlist",
"created_at": "2019-12-12T21:42:11.346Z",
"updated_at": "2019-12-12T21:42:11.346Z"
}
]
Update a playlist. To update a playlist title, a unique playlist title must be included in the POST request body.
PUT /api/v1/playlists/:id
title
: title of playlist
If successful, application will respond with 201 status and return JSON of newly updated playlist record.
Sample Successful Response:
[
{
"id": 2,
"title": "Classical Playlist",
"created_at": "2019-12-11T19:40:01.088Z",
"updated_at": "2019-12-11T19:40:01.088Z"
}
]
Delete a single playlist from the database
DELETE /api/v1/playlists/:id
:id
: id of the track to be deleted
If successful, application will respond with 201 status.
Returns a playlist with it associated favorite tracks from the database
GET /api/v1/playlists/:id/favorites
:id
: id of desired favorite track
If successful, application will respond with status code 200 and JSON of requested playlists with associated favorite tracks.
Sample Successful Response:
{
"id": 1,
"title": "90s Guilty Pleasure",
"songCount": 1,
"songAvgRating": 88,
"favorites": [
{
"id": 1,
"title": "Bailamos",
"artistName": "Enrique Iglesias",
"genre": "Pop",
"rating": 88
}
],
"updated_at": "2019-12-11T19:40:01.088Z",
"created_at": "2019-12-11T19:40:01.088Z"
}
Add a favorite track to a playlist. A playlist id and favorite id must be included in the POST request URI.
POST /api/v1/playlists/:playlist_id/favorites/:favorite_id
playlist_id
: id of playlist
favorite_id
: id of favorite
If successful, application will respond with 201 status and return message indicating that the favorite track has been added to the playlist.
Sample Successful Response:
{
"Success": "Bailamos has been added to 90s Guilty Pleasure!"
}
Delete a favorite track from a playlist. A playlist id and favorite id must be included in the DELETE request URI.
DELETE /api/v1/playlists/:playlist_id/favroites/:favorite_id
playlist_id
: id of playlist
favorite_id
: id of favorite
If successful, application will respond with 201 status.