MackHalliday / play-play-express

API with CRUD functionality for favorite tracks and playlists. Uses MusixMatch API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Play Play

Build Status

Table of Contents

Introduction

Intial Setup

Follow the following steps to setup application locally. Setup time is 5-10 minutes.

Installing necessary dependencies

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

Set up your local database

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;.

Migrations

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

Adding Environment Keys

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

Set up your test database

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.

How to Run Tests

Running tests are simple and require you to run the following command below:

npm test

How to Use

We recommend using Postman to hit endpoints.

Endpoints

Root

Production address

https://play-play-express.herokuapp.com/

Local address

http://localhost:3000/

Get All Favorite Tracks

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.

Run in Postman

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
    }
]

Get a Single Favorite Track

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.

Run in Postman

Sample Successful Response:

[
    {
        "id": 2,
        "title": "The Chain",
        "artistName": "Fleetwood Mac",
        "genre": "Rock",
        "rating": 52
    }
]

Delete a Single Favorite Track

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.

Run in Postman

Add a New Single Favorite Track

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.

Run in Postman

Sample Successful Response:

[
    {
        "id": 19,
        "title": "Stronger",
        "artistName": "Kelly Clarkson",
        "genre": "Electronic",
        "rating": 30
    }
]

Get All Playlists

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.

Run in Postman

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 Single Playlist

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.

Run in Postman

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 Single Playlist

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.

Run in Postman

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

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.

Run in Postman

Get a Single Playlist with Favorites

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.

Run in Postman

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 Single Favorite to a Playlist

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.

Run in Postman

Sample Successful Response:

{
    "Success": "Bailamos has been added to 90s Guilty Pleasure!"
}

Delete a Single Favorite from a Playlist

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.

Run in Postman

Schema Design

image

Tech Stack List

Core Contributors

View LinkedIn

View LinkedIn

About

API with CRUD functionality for favorite tracks and playlists. Uses MusixMatch API


Languages

Language:JavaScript 99.4%Language:HTML 0.4%Language:CSS 0.2%