Endpoint for product reviews
- express v4.17.1
- mysql2 v2.3.3
- nodemon v2.0.15
- dotenv v10.0.0
- Node.js ≥ v14
- MySQL ≥ v5.7
After forking and cloning down the repo, create a .env
file in the root directory with the same keys listed in dotenv.example.txt
. Ensure that the .env
file is gitignored.
Run the following commands from the root directory:
$ npm install
to install all necessary dependencies
$ mysql -u <username> -p <password> < database/schema.sql
to seed the database schema
Ensure the mysql server on your machine is running and then
$ npm start
to start the nodemon server.
For load balancing setup, see nginx.example.conf
.
Returns a list of reviews for a particular product. This list does not include any reported reviews.
GET /reviews
Query parameters:
Parameter | Type | Description |
---|---|---|
page |
integer | Selects the page of results to return - default 1 |
count |
integer | Specifies how many results per page to return - default 5. |
sort |
string | Changes the sort order of reviews to be based on "newest", "helpful", or "relevant" |
product_id |
integer | Specifies the product for which to retrieve reviews. |
Response:
Status: 200 OK
Adds a review for the given product.
POST /reviews
Body parameters:
Parameter | Type | Description |
---|---|---|
product_id |
integer | Required ID of the product to post the review for |
rating |
integer | 1-5 indicating the review rating |
summary |
string | (optional) Summary text of the review - if none, the empty string "" should be sent |
body |
string | Continued or full text of the review |
recommend |
boolean | Value indicating if the reviewer recommends the product |
name |
string | Username for question asker |
email |
string | Email address for question asker |
photos |
JSON array | Array of string urls that link to images to be shown |
characteristics |
JSON object | Object of keys representing characteristic_id and values representing the review value for that characteristic. { "14": 5, "15": 5 //...} |
Response:
Status: 201 CREATED