/SingMeASong_BackEnd

This is an API for people like me, who passes more time choosing the musics than listening to them

Primary LanguageJavaScript

Sing me a Song API

About

Are you very undecided? Well, I am, but we are lucky internet has become a life savior. In this API you can post some musics, upvote the ones you like the most and downvote the ones you don't enjoy. Based on those actions, Sing me a Song API has an algorithm which returns randomly the musics you've posted. You can also get your top voted musics only by setting the amount you want. Isn't that awesome? Your "I don't know which music I wanna choose" moments are over!!

Features

The API has the following endpoints:

POST /recommendations
  • Adds a new music recommendation. The requisition has to follow the pattern bellow:

    {
    	"name": "PingFong - Baby Shark",
    	"youtubeLink": "https://www.youtube.com/watch?v=XqZsoesa55w",
    }
    • Validation
      • name must follow the pattern "Artist - Name"
      • youtubeLink must be a youtube domain link
    • Return
      • Returns the JSON of the music you've registered:
        {
          "id": 5,
          "name": "PingFong - Baby Shark",
          "score": 0,
          "youtubeLink": "https://www.youtube.com/watch?v=XqZsoesa55w"
        }
POST /recommendations/:id/upvote
  • Adds a point to the score of the recommendation you've chosen.
  • Returns the recommendation with the new score
POST /recommendations/:id/downvote
  • Remove a point of the recommendation you've chosen.
  • If the score gets bellow -5, the recommendation'll be deleted.
  • Returns the recommendation with the new score
GET /recommendations/random

Receives a random recommendation based on the algorithm bellow:

  • 70% of the times: a music which score is above 10 will be recommended randomly;

  • 30% of the times: a música which score is between -5 e 10 (included) will be recommended randomly;

  • In case there are only above 10 scores or only bellow or equal to 10 scores, any music will be recommended;

  • In case there are no musics on the database, a statusCode 404 will be returned;

  • The answer will follow the pattern bellow:

       ```json
          {
            "id": 5,
            "name": "PingFong - Baby Shark",
            "score": 230,
            "youtubeLink": "https://www.youtube.com/watch?v=XqZsoesa55w"
          }
          ```
    
GET /recommendations/top/:amount

Returns the musics with the highest scores. Returns the top x(:amount parameter of the endpoint) musics, sorted by score (highest first)

        [
            {
              "id": 5,
              "name": "PingFong - Baby Shark",
              "score": 230,
              "youtubeLink": "https://www.youtube.com/watch?v=XqZsoesa55w"
            },
            {
                "id": 12,
                "name": "George Michael - Careless Whispers",
                "youtubeLink": "https://www.youtube.com/watch?v=izGwDsrQ1eQ",
                "score": 112
            },
            ...
        ]

How to run?

You can use this url to make your requisitions: https://sing-me-a-song-backend.herokuapp.com, or run it locally following the steps bellow:

  1. Clone this repository
  2. Install dependencies
npm i
  1. Open the repository's folder;

  2. Open the file "database_backup.sql", then copy and paste the script on some database you'll create on your postgres terminal;

  3. create an .env.dev file following the .env.example template using the credentials of the database you've created above;

  4. Run the Back End with

npm start:dev

What comes next?

  • On the next versions the musics will be organized by genres so you can listen tio the one you're in the mood;
  • There'll be a plataform where you can try the API and will not be demmanded to use JSON formats;

Tests Coverage

Screen Shot 2021-12-05 at 00 30 12

Tecnologies I Used

NodeJS ExpressJS PostgreSQL Jest

Get in touch!

Gmail Badge Instagram Github WhatsApp