REVIEW API

Endpoints

1. Create a Review (POST)

  • URL: /api/review
  • Method: POST
  • Authorization: Bearer token (JWT)
  • Body Parameters (JSON):
    • road_id (int): The ID of the road being reviewed.
    • description (string): The description of the review.
    • rating (int): Rating of the road (1-5).
  • Response (Success):
    • Code: 200 OK
    • Body: The created review details in JSON format.
  • Response (Failure):
    • Code: 400 Bad Request{'message': 'bad data'}
    • Code: 404 Not Found{'message': 'road not found'}

2. Get All Reviews (GET)

  • URL: /api/review
  • Method: GET
  • Authorization: None
  • Response (Success): 200 OK — List of all reviews in JSON
  • Response (Failure): 404 Not Found{'message': 'Reviews not found'}

3. Update a Review (PUT)

  • URL: /api/review
  • Method: PUT
  • Authorization: Bearer token (JWT)
  • Body Parameters (JSON):
    • id (int): Review ID
    • description (string): Updated text
    • rating (int): Updated score (1-5)
  • Response (Success):
    • Code: 200 OK — Updated review in JSON
  • Response (Failure):
    • Code: 404{'message': 'review not found'}
    • Code: 401{'message': 'can not update review'}

4. Delete a Review (DELETE)

  • URL: /api/review
  • Method: DELETE
  • Authorization: Bearer token (JWT)
  • Body Parameters:
    • id (int): ID of the review
  • Response (Success): 200 OK{ "message": "Road removed", "deleted": true }
  • Response (Failure):
    • 401{ "message": "Road not deleted wrong user", "deleted": false }
    • 404{ "message": "review not found" }

Example Request & Response

Create a Review (POST)

Request:

POST /api/review
  Content-Type: application/json
  Authorization: Bearer <your_token>

  {
    "road_id": 1,
    "description": "The road is in good condition.",
    "rating": 5
  }

Response:

{
    "id": 123,
    "user_id": 1,
    "road_id": 1,
    "description": "The road is in good condition.",
    "rating": 5,
    "created_at": "2025-04-25T00:00:00Z"
  }