Class ReviewService
java.lang.Object
com.goldenleaf.shop.service.ReviewService
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 Summary
ConstructorsConstructorDescriptionConstructs a newReviewServicewith the provided repository. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a newReviewto the database.voideditReview(Review review) Updates an existingReview.Retrieves all reviews from the database.getAllReviewsByProduct(Product product) Retrieves all reviews associated with a specific product.getAllReviewsOfCustomer(Customer customer) Retrieves all reviews made by a specific customer.Retrieves all reviews made by a customer identified by their login.getReviewById(Long id) Retrieves aReviewby its unique ID.getReviewsByCustomer(Customer customer) Retrieves reviews for a specific customer.getReviewsByCustomerLogin(String login) Retrieves reviews for a customer identified by login.getReviewsByProduct(Product product) Retrieves reviews for a specific product.Retrieves reviews for a product by its name.voidremovebyProduct(Product product) Removes all reviews associated with a specific product.voidremovebyProductName(String name) Removes all reviews associated with a product identified by name.voidremoveReview(Review review) Removes an existingReviewfrom the database.voidremoveReviewById(Long id) Removes aReviewby its ID.
-
Constructor Details
-
ReviewService
Constructs a newReviewServicewith the provided repository.- Parameters:
repo- the repository used to perform operations on reviews- Throws:
IllegalArgumentException- ifrepoisnull- See Also:
-
-
Method Details
-
getAllReviews
-
getAllReviewsByProduct
-
getAllReviewsOfCustomer
-
getAllReviewsOfCustomerLogin
-
getReviewById
Retrieves aReviewby its unique ID.- Parameters:
id- the ID of the review- Returns:
- the
Reviewwith the specified ID - Throws:
RuntimeException- if no review with the given ID exists- See Also:
-
addReview
-
removeReview
-
removeReviewById
-
editReview
Updates an existingReview.The review must have a valid ID that exists in the database. Otherwise, a
RuntimeExceptionis thrown.- Parameters:
review- the review to update- Throws:
RuntimeException- if the review does not exist or ID is null- See Also:
-
getReviewsByCustomer
-
getReviewsByCustomerLogin
-
getReviewsByProduct
-
getReviewsByProductName
-
removebyProduct
-
removebyProductName
Removes all reviews associated with a product identified by name.- Parameters:
name- the name of the product whose reviews should be deleted- See Also:
-