Class ReviewService

java.lang.Object
com.goldenleaf.shop.service.ReviewService

public class ReviewService extends Object
Service class for managing Review entities.

Provides business logic for retrieving, adding, updating, and deleting reviews. Supports filtering reviews by Product, Customer, and customer login. Acts as an intermediary between controllers and the ReviewRepository.

See Also:
  • Constructor Details

  • Method Details

    • getAllReviews

      public List<Review> getAllReviews()
      Retrieves all reviews from the database.
      Returns:
      a List of all Review entities
      See Also:
      • ListCrudRepository.findAll()
    • getAllReviewsByProduct

      public List<Review> getAllReviewsByProduct(Product product)
      Retrieves all reviews associated with a specific product.
      Parameters:
      product - the Product for which reviews are retrieved
      Returns:
      a List of reviews for the specified product
      See Also:
    • getAllReviewsOfCustomer

      public List<Review> getAllReviewsOfCustomer(Customer customer)
      Retrieves all reviews made by a specific customer.
      Parameters:
      customer - the Customer whose reviews are retrieved
      Returns:
      a List of reviews by the specified customer
      See Also:
    • getAllReviewsOfCustomerLogin

      public List<Review> getAllReviewsOfCustomerLogin(String login)
      Retrieves all reviews made by a customer identified by their login.
      Parameters:
      login - the login of the customer
      Returns:
      a List of reviews by the customer with the given login
      See Also:
    • getReviewById

      public Review getReviewById(Long id)
      Retrieves a Review by its unique ID.
      Parameters:
      id - the ID of the review
      Returns:
      the Review with the specified ID
      Throws:
      RuntimeException - if no review with the given ID exists
      See Also:
      • CrudRepository.findById(Object)
    • addReview

      public void addReview(Review review)
      Adds a new Review to the database.
      Parameters:
      review - the review to add
      See Also:
      • CrudRepository.save(Object)
    • removeReview

      public void removeReview(Review review)
      Removes an existing Review from the database.

      If the review exists (by ID), it will be deleted; otherwise, nothing happens.

      Parameters:
      review - the review to remove
      See Also:
      • CrudRepository.delete(Object)
      • CrudRepository.existsById(Object)
    • removeReviewById

      public void removeReviewById(Long id)
      Removes a Review by its ID.
      Parameters:
      id - the ID of the review to delete
      See Also:
      • CrudRepository.deleteById(Object)
    • editReview

      public void editReview(Review review)
      Updates an existing Review.

      The review must have a valid ID that exists in the database. Otherwise, a RuntimeException is thrown.

      Parameters:
      review - the review to update
      Throws:
      RuntimeException - if the review does not exist or ID is null
      See Also:
      • CrudRepository.save(Object)
      • CrudRepository.existsById(Object)
    • getReviewsByCustomer

      public List<Review> getReviewsByCustomer(Customer customer)
      Retrieves reviews for a specific customer.
      Parameters:
      customer - the Customer whose reviews are retrieved
      Returns:
      a List of reviews
      See Also:
    • getReviewsByCustomerLogin

      public List<Review> getReviewsByCustomerLogin(String login)
      Retrieves reviews for a customer identified by login.
      Parameters:
      login - the login of the customer
      Returns:
      a List of reviews
      See Also:
    • getReviewsByProduct

      public List<Review> getReviewsByProduct(Product product)
      Retrieves reviews for a specific product.
      Parameters:
      product - the Product whose reviews are retrieved
      Returns:
      a List of reviews
      See Also:
    • getReviewsByProductName

      public List<Review> getReviewsByProductName(String name)
      Retrieves reviews for a product by its name.
      Parameters:
      name - the name of the product
      Returns:
      a List of reviews
      See Also:
    • removebyProduct

      public void removebyProduct(Product product)
      Removes all reviews associated with a specific product.
      Parameters:
      product - the Product whose reviews should be deleted
      See Also:
    • removebyProductName

      public void removebyProductName(String name)
      Removes all reviews associated with a product identified by name.
      Parameters:
      name - the name of the product whose reviews should be deleted
      See Also: