API - Sing me a song

About the project

Sing me a song is API to post songs from youtube and get random or top songs recommendations ranked by 'points'. It is also possible to Upvote or Downvote a song.

Routes

  • GET /recommendations/random

Response is 70% a random song recommendation above 10 in points and 30% a random song. Response example:

[
  {
    "id": 8,
    "name": "Bon Jovi - Livin' On A Prayer",
    "ytblink": "https://www.youtube.com/watch?v=lDK9QqIzhwk",
    "points": 12
  }
]
  • GET /recommendations/top/:amount

Response is the top amount recommendations ranked by points. Response example for amount = 3:

[
  {
    "id": 8,
    "name": "Bon Jovi - Livin' On A Prayer",
    "ytblink": "https://www.youtube.com/watch?v=lDK9QqIzhwk",
    "points": 12
  },
  {
    "id": 9,
    "name": "Three Days Grace - Pain",
    "ytblink": "https://www.youtube.com/watch?v=Ud4HuAzHEUc",
    "points": 10
  },
    {
    "id": 10,
    "name": "Breaking The Habit - Linkin Park",
    "ytblink": "https://www.youtube.com/watch?v=v2H4l9RpkwM",
    "points": 8
  }
]
  • POST /recommendations

Requires a body like:

{
    "name": "Bon Jovi - Livin' On A Prayer",
    "youtubeLink": "https://www.youtube.com/watch?v=lDK9QqIzhwk"
}

Response is the data of the posted body. Response example:

[
  {
    "id": 8,
    "name": "Bon Jovi - Livin' On A Prayer",
    "ytblink": "https://www.youtube.com/watch?v=lDK9QqIzhwk",
    "points": 0
  }
]
  • POST /recommendations/:id/upvote

Increases the points of recommendation by 1.
Response is the data of the upvoted recommendation. Response example for id = 8:

[
  {
    "id": 8,
    "name": "Bon Jovi - Livin' On A Prayer",
    "ytblink": "https://www.youtube.com/watch?v=lDK9QqIzhwk",
    "points": 1
  }
]
  • POST /recommendations/:id/downvote

Decreases the points of recommendation by 1. If a recommendation gets below -5 points, it is deleted from the DB
Response is the data of the downvoted recommendation (for deleted ones is 400 status code). Response example for id = 8:

[
  {
    "id": 8,
    "name": "Bon Jovi - Livin' On A Prayer",
    "ytblink": "https://www.youtube.com/watch?v=lDK9QqIzhwk",
    "points": 0
  }
]

Tech Stack

The following tools were used in the construction of the project-api:

Server (NodeJS)

Utilities



Getting Started

Prerequisites

  • npm

Installation

  1. Clone this repository
https://github.com/pedrohotz/SingMeASongAPI.git
  1. Install the dependencies executing command
npm i
  1. Create a .env file in folder (root) like the .env.example file and fill with your values.

  2. Create a postgres database.


  3. Run dump to populate DB.



How to run

  1. Start the API
npm run start
  1. To run Tests
npm run test

How to contribute

  1. Fork the project.
  2. Create a new branch with your changes: git checkout -b feat/myFeatureName
  3. For each feature implemented, make a commit specifying what was done
  4. Submit your changes: git push -u origin feat/myFeatureName

Author

Developed by Pedro Hotz Bronzato.