FORK_backend_docs

Review API

Table of Contents


GET : get review by query

URL

/api/reviews

Request Format

Location Field Name Data Type Required Description
query facility int - unique id of facility
query user int - unique id of user
query hasImage bool - if true then return reviews that contain images
query hashtags array - an array of hashtag.id integers. will return reviews that contain 1 or more of the hashtags provided

Response Format

Key Description
status success
data array of objects that contain columns of review, hashtag tables. This means it gets reviews along with all the associated hashtag data.

GET : get review by ID

URL

/api/reviews/:id

Request Format

Location Field Name Data Type Required Description
param id int O unique id of the review

Response Format

Key Description
status success
data the returned review object + all associated hashtag

POST : Create a Review

URL

/api/reviews/upload

Request Format

Location Field Name Data Type Required Description
body authorId int O the unique id of the user who is the author of the review
body facilityId int O the unique id of the facility
body score int O the review score, which is an integer value in range [0, 5]
body content string O review contents, which is text
body hashtags JSON-string O a JSON-strint of an array of hashtag names to be inserted ex. ['hashtag 1', 'hashtag 2']
body-FormData image file - the image file to upload

Request Body - hashtags

{
    "hashtags": ["Good Food", "A New Hashtag"]
}

Response Format

Key Description
status success
data the created review object + all associated hashtag

Response Format - Moderation

Key Description
status error
message "review upload failed due to harmful content detected"
data object containing content moderation result { status, message, image, text } keys image, text include data & scores for each moderation result.

Example Response - Moderation

{
  "status": "error",
  "message": "review upload failed due to harmful content detected",
  "data": {
    "status": 499,
    "message": "review upload failed due to harmful content detected",
    "text": {
      "result": true,
      "data": {
        "sexual": 0.09,
        "discriminatory": 0.08,
        "insulting": 0.86,
        "violent": 0.04,
        "toxic": 0.87
      }
    },
    "image": {
      "result": true,
      "data": {
        "nudity": 0.030000000000000027,
        "offensive": 0.89,
        "gore": 0.01,
        "textProfanity": []
      }
    }
  }
}

Notes


POST : Edit Review Contents - Text & Hashtags

URL

/api/reviews/:id

Request Format

Location Field Name Data Type Required Description
param id int O unique id of the review
body content string O review contents, which is text
body hashtags JSON-string O a JSON-strint of an array of hashtag names to be inserted ex. ['hashtag 1', 'hashtag 2']

Response Format

Key Description
status success
data the updated review object + all associated hashtag

DELETE : Delete a Review

URL

/api/reviews/:id

Request Format

Location Field Name Data Type Required Description
param id int O unique id of the review

Response Format

Key Description
status success
data the deleted review object (no hashtags)

GET : Get a Summary of reviews for a Faciltiy

URL

/api/reviews/summary/:facility

Request Format

Location Field Name Data Type Required Description
param facility int O the unique id of the facility
query force bool - if set to true this will force-recreate the summary rather than using a cached one. The constraint of facility needing more than 3 reviews will still apply. ONLY USE THIS FOR DEVELOPMENT & TEST PURPOSES

Response Format

Key Description
status success
data data format is { id, summary }, id = facilityId, summary = the generated text summary

Notes : Criteria for generating a summary


Hashtag Methods


GET : Get all Hashtags from the system

URL

/api/hashtags/

Request Format

Location Field Name Data Type Required Description
. . . . .

Response Format

Key Description
status success
data array of hashtag rows

GET : Get a Hashtag by ID

URL

/api/hashtags/:id

Request Format

Location Field Name Data Type Required Description
param id int O unique id of the hashtag

Response Format

Key Description
status success
data the returned hashtag object

GET : Get Top-N Hashtags of a Facility

URL

/api/hashtags/top/:facility

Request Format

Location Field Name Data Type Required Description
param facility int O the unique id of the facility
query limit int - limit the returned hashtag rows to this amount. If not given, the result will contain every hashtag that appears at least once

Response Format

Key Description
status success
data array of hashtag rows