diff --git a/ThunderClient/EndpointTests.json b/ThunderClient/EndpointTests.json index 88ace4e..75a6e28 100644 --- a/ThunderClient/EndpointTests.json +++ b/ThunderClient/EndpointTests.json @@ -1,7 +1,7 @@ { "client": "Thunder Client", "collectionName": "SmartInventory", - "dateExported": "2024-03-29T17:03:34.803Z", + "dateExported": "2024-03-29T20:18:38.621Z", "version": "1.1", "folders": [ { @@ -411,6 +411,46 @@ } ], "tests": [] + }, + { + "_id": "2c1865fa-1561-44ff-89ca-ac310a29a3f9", + "colId": "e34b9201-d6f7-4614-a21c-21c245c1032e", + "containerId": "0db7fba9-c06d-462f-a621-ce608d52ea78", + "name": "Search by Product ID", + "url": "http://localhost:9090/reviews/products/{productId}", + "method": "GET", + "sortNum": 150000, + "created": "2024-03-29T19:23:28.542Z", + "modified": "2024-03-29T19:35:16.675Z", + "headers": [], + "params": [ + { + "name": "productId", + "value": "3", + "isPath": true + } + ], + "tests": [] + }, + { + "_id": "db42fe54-ccdc-4f85-899c-643aba8abe2a", + "colId": "e34b9201-d6f7-4614-a21c-21c245c1032e", + "containerId": "0db7fba9-c06d-462f-a621-ce608d52ea78", + "name": "Search by Customer", + "url": "http://localhost:9090/reviews/customers/{id}", + "method": "GET", + "sortNum": 160000, + "created": "2024-03-29T19:33:42.375Z", + "modified": "2024-03-29T19:35:37.747Z", + "headers": [], + "params": [ + { + "name": "id", + "value": "1", + "isPath": true + } + ], + "tests": [] } ] } \ No newline at end of file diff --git a/src/main/java/sg/com/smartinventory/controllers/ReviewController.java b/src/main/java/sg/com/smartinventory/controllers/ReviewController.java index 362ee56..ef22913 100644 --- a/src/main/java/sg/com/smartinventory/controllers/ReviewController.java +++ b/src/main/java/sg/com/smartinventory/controllers/ReviewController.java @@ -53,6 +53,18 @@ public ArrayList getRatings(@Valid @RequestParam int rating) { return reviewService.getRatings(rating); } + // READ (Search by customer Id) + @GetMapping("/customers/{id}") + public ArrayList searchReviewByCustomerId(@PathVariable long id) { + return reviewService.searchCustomerReviews(id); + } + + // READ (Search by product Id) + @GetMapping("/products/{productId}") + public ArrayList searchReviewByProductId(@PathVariable long productId) { + return reviewService.searchProductReviews(productId); + } + // UPDATE. @PutMapping("/{id}") public ResponseEntity updateReview(@PathVariable long id, @RequestBody Review review) { diff --git a/src/main/java/sg/com/smartinventory/entities/Customer.java b/src/main/java/sg/com/smartinventory/entities/Customer.java index fa50cae..dc79211 100644 --- a/src/main/java/sg/com/smartinventory/entities/Customer.java +++ b/src/main/java/sg/com/smartinventory/entities/Customer.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; - import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/sg/com/smartinventory/serviceImpls/ReviewServiceImpl.java b/src/main/java/sg/com/smartinventory/serviceImpls/ReviewServiceImpl.java index 77eba74..8de9a5a 100644 --- a/src/main/java/sg/com/smartinventory/serviceImpls/ReviewServiceImpl.java +++ b/src/main/java/sg/com/smartinventory/serviceImpls/ReviewServiceImpl.java @@ -21,7 +21,7 @@ public class ReviewServiceImpl implements ReviewService { private ProductRepository productRepository; // @Autowired - public ReviewServiceImpl(ReviewRepository reviewRepository) { + public ReviewServiceImpl(ReviewRepository reviewRepository, ProductRepository productRepository) { this.reviewRepository = reviewRepository; this.productRepository = productRepository; } @@ -43,7 +43,7 @@ public ArrayList searchCustomerReviews(long customerId) { @Override public ArrayList searchProductReviews(long productId) { Product product = productRepository.findById(productId).orElseThrow(() -> new ProductNotFoundException(productId)); - List foundReviews = reviewRepository.findByProductId(productId); + List foundReviews = reviewRepository.findByProductId(product.getId()); return (ArrayList) foundReviews; }