Class DB2024TEAM07_ReviewDAO

java.lang.Object
com.jdbc.database.DB2024TEAM07_ReviewDAO

public class DB2024TEAM07_ReviewDAO extends Object
This class provides data access object (DAO) methods for interacting with the DB2024_Review and related tables in a database. It manages various functionalities related to user reviews, restaurant reviews, and review management.
  • Field Details

  • Constructor Details

    • DB2024TEAM07_ReviewDAO

      public DB2024TEAM07_ReviewDAO()
      Constructor that establishes a connection to the database using the DB2024TEAM07_Database class.
  • Method Details

    • add

      public int add(DB2024TEAM07_Review review, int menuId, int resId)
      Adds a new review to the database.
      Parameters:
      review - the review object containing user ID, rating, and review content
      menuId - the ID of the menu associated with the review
      resId - the ID of the restaurant associated with the review
      Returns:
      1 on successful insertion, -1 if the review ID cannot be generated, or -2 on an error
    • update

      public int update(DB2024TEAM07_Review review)
      Updates an existing review in the database.
      Parameters:
      review - the review object containing updated rating and review content
      Returns:
      the number of rows affected (1 for a successful update) or -2 on an error
    • getCount

      public int getCount()
      Retrieves the total number of reviews in the database.
      Returns:
      the total count of reviews as an integer
    • getReview

      public ArrayList<DB2024TEAM07_Review> getReview(int page)
      Retrieves a paginated list of reviews from the database, ordered by review ID in descending order.
      Parameters:
      page - the page number (starting from 1) to retrieve
      Returns:
      a list of `DB2024TEAM07_Review` objects representing the reviews for that page
    • getUserCount

      public int getUserCount(String user_id)
      Retrieves the total number of reviews for a specific user.
      Parameters:
      user_id - the ID of the user
      Returns:
      the total count of reviews for that user as an integer
    • getUserReview

      public ArrayList<DB2024TEAM07_ResReviewVO> getUserReview(int page, String user_id)
      Retrieves a paginated list of reviews for a specific user, ordered by review ID in descending order.
      Parameters:
      page - the page number (starting from 1) to retrieve
      user_id - the ID of the user
      Returns:
      a list of `DB2024TEAM07_ResReviewVO` objects representing the reviews for that user and page
    • getResCount

      public int getResCount(int res_id)
      Retrieves the total number of reviews for a specific restaurant.
      Parameters:
      res_id - the ID of the restaurant
      Returns:
      the total count of reviews for that restaurant as an integer
    • getResReview

      public ArrayList<DB2024TEAM07_UserReview> getResReview(int page, int res_id)
      Retrieves a paginated list of reviews for a specific restaurant, ordered by review ID in descending order.
      Parameters:
      page - the page number (starting from 1) to retrieve
      res_id - the ID of the restaurant
      Returns:
      a list of `DB2024TEAM07_UserReview` objects representing the reviews for that restaurant and page
    • delete

      public int delete(int review_id)
      Deletes a review from the database.
      Parameters:
      review_id - the ID of the review to delete
      Returns:
      the number of rows affected (1 for a successful deletion) or -2 on an error