ThVinicius / sing_me_a_song_backEnd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

projeto21-sing me a song

In this project I was given the task of doing the unit tests, integration and e2e

Sing me a song

Built With


Description

Sing me a song is an application for anonymous song recommendation. The more people like a recommendation, the more likely it is to be recommended to others.


Testes


API Reference

Create recommendation

POST /recommendations

Request:

Params Type Description
name string Required
youtubeLink string Required, youtube link

Response:

Error cases:

Status code Cause
400 Request in wrong format
409 try to register with an name already registered

Success case (status code 201)

Add a point to the recommendation score.

POST /recommendations/:id/upvote

Response:

Error cases:

Status code Cause
404 id not found

Success case (status code 200:)

Removes one point from the recommendation score.

If the score falls below -5, the recommendation should be deleted.

POST /recommendations/:id/downvote

Response:

Error cases:

Status code Cause
404 id not found

Success case (status code 200:)

Get all the last 10 recommendations.

GET /recommendations

Response:

Success case (status code 200:)

[
  {
    "id": 1,
    "name": "Chitãozinho E Xororó - Evidências",
    "youtubeLink": "https://www.youtube.com/watch?v=ePjtnSPFWK8&ab_channel=CHXVEVO",
    "score": 245
  }
]

Get a recommendation by your ID.

GET /recommendations/:id

Response:

Error cases:

Status code Cause
404 id not found

Success case (status code 200:)

{
  "id": 1,
  "name": "Chitãozinho E Xororó - Evidências",
  "youtubeLink": "https://www.youtube.com/watch?v=ePjtnSPFWK8&ab_channel=CHXVEVO",
  "score": 245
}

Take a random recommendation.

  • 70% of the times they hit this route: a song with a score greater than 10 should be randomly recommended
  • 30% of the times they hit this route: a song with a score between -5 and 10 (inclusive), should be randomly recommended
  • If there are only songs with a score above 10 or only below/equal to 10, 100% of the time any song must be drawn
  • If there is no song registered, status 404 must be returned
GET /recommendations/random

Response:

Success case (status code 200:)

{
	"id": 1,
	"name": "Chitãozinho E Xororó - Evidências",
	"youtubeLink": "https://www.youtube.com/watch?v=ePjtnSPFWK8&ab_channel=CHXVEVO",
	"score": 245
},

List the best recommendations.

  • Lists the songs with the most points and their score. Top x songs are returned (parameter :amount of the route), ordered by score (highest first)
GET /recommendations/top/:amount

Response:

Success case (status code 200:)

[
	{
		"id": 150,
		"name": "Chitãozinho E Xororó - Evidências",
		"youtubeLink": "https://www.youtube.com/watch?v=ePjtnSPFWK8&ab_channel=CHXVEVO",
		"score": 245
	},
	{
		"id": 12,
		"name": "Falamansa - Xote dos Milagres",
		"youtubeLink": "https://www.youtube.com/watch?v=ePjtnSPFWK8&ab_channel=CHXVEVO",
		"score": 112
	},
	...
]

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

DATABASE_URL = postgres://UserName:Password@Hostname:5432/DatabaseName

PORT = number #recommended:5000

NODE_ENV = string #TEST if it is a dev environment


Run Locally

Clone the project

  git clone https://github.com/ThVinicius/sing_me_a_song_backEnd.git

Go to the project directory

  cd sing_me_a_song_backEnd

Install dependencies

  npm install

Create database

  npx prisma migrate dev

Start the server

  npm run start

Run tests

  npm test

Acknowledgements


Authors

  • Vinicius Pacheco is a student at Driven Education and is putting effort into it to switch careers. Nowadays he works with Engineering, looking forward to become a Dev.

About


Languages

Language:TypeScript 97.2%Language:JavaScript 2.7%Language:Shell 0.1%