Skip to content
Marah edited this page Nov 3, 2024 · 4 revisions

Review Module Documentation

Overview

The review module manages user and rental reviews, allowing renters to add, view, edit, and delete reviews. This module also includes functionality for searching reviews, checking and sending coupons to users, and updating user ratings based on reviews.


Function: addUserReview

Purpose

This function allows a renter to add a new review for another user who rented an item from him.

Endpoint

POST /review/user

Workflow

  1. Extract Review Details: Retrieves the required data from the request body.
  2. Validation: Validates that the necessary fields are provided.
  3. Insert Review Record: Adds the review to the Review table with relevant details, including the reviewer and reviewee IDs, rating, and comment.
  4. Response: Returns a success message or an error if any issues arise during insertion.

Function: addRentalReview

Purpose

This function allows users to add reviews specifically for rentals.

Endpoint

POST /review/rental

Workflow

  1. Extract Review Details: Gathers the rental review data from the request body.
  2. Validation: Checks for necessary fields.
  3. Insert Rental Review Record: Adds a new review to the Review table, associating it with the specific rental.
  4. Response: Sends a confirmation message upon successful insertion.

Function: viewRentalReview

Purpose

Fetches all reviews related to a specific rental by rental_id.

Endpoint

GET /review/Rental/:rental_id

Workflow

  1. Rental ID Extraction: Retrieves the rental_id from the URL parameters.
  2. Database Query: Finds all reviews associated with the provided rental_id.
  3. Response: Returns a list of reviews for the rental or an error if none are found.

Function: viewUserReviews

Purpose

Retrieves all reviews for a particular user by Userid.

Endpoint

GET /review/User/:Userid

Workflow

  1. User ID Extraction: Extracts Userid from the URL parameters.
  2. Database Query: Retrieves reviews where the target is the specified user.
  3. Response: Returns the list of user reviews or an error if none are found.

Function: editReview

Purpose

Enables a user to edit an existing review that they authored.

Endpoint

PUT review/:review_id/:reviewer_id

Workflow

  1. Extract Review ID and Reviewer ID: Retrieves these IDs from the URL parameters.
  2. Validation and Authorization Check: Confirms that the review exists and the reviewer_id matches the authenticated user.
  3. Update Review Content: Modifies the review content based on new information provided in the request body.
  4. Response: Sends a success message or error message if the update fails.

Function: deleteReviews

Purpose

Allows users to delete a review they have authored by providing the review_id.

Endpoint

DELETE /review/:review_id

Workflow

  1. Extract Review ID: Gets review_id from the URL parameters.
  2. Authorization Check: Confirms that the user has permission to delete this review.
  3. Delete Review: Removes the review from the Review table.
  4. Response: Sends a confirmation message upon successful deletion.

Function: searchReview

Purpose

Searches for reviews based on a keyword.

Endpoint

GET /review/data/:name

Workflow

  1. Extract Search Keyword: Gets name from the URL parameters.
  2. Database Query: Searches the Review table for reviews that match the keyword.
  3. Response: Returns a list of reviews that match the search criteria.

Function: checkAndSendCoupon

Purpose

Checks the eligibility of a user for a coupon and sends it via chatting if eligible.

Endpoint

GET /review/send-coupon/:user_id

Workflow

  1. User ID Extraction: Gets user_id from the URL parameters.
  2. Eligibility Check: Verifies if the user qualifies for a coupon.
  3. Send Coupon: If eligible, sends a coupon to the user.
  4. Response: Returns a success message if the coupon is sent or an error if not eligible.

Function: updateUserRatings

Purpose

Updates a user’s rating based on the average of all received reviews.

Endpoint

PUT /review/update-user-ratings

Workflow

  1. Extract User ID: Obtains the user_id from the request body.
  2. Calculate New Rating: Computes the average rating from all reviews for the specified user.
  3. Update User Record: Updates the user’s rating in the users table.
  4. Response: Returns a success message upon successful rating update.

Example Request for /review/user

POST /review/user
Content-Type: application/json

{ "reviewer_id":1 , "reviewer_user_id":2 , "rating":4.5 , "comment":"this person is reliable " }

Clone this wiki locally