Skip to content

Commit

Permalink
Merge pull request #25 from kiblykat/sis-41c
Browse files Browse the repository at this point in the history
SIS-41, added search review endpoints.
  • Loading branch information
nhkhai authored Mar 30, 2024
2 parents a704b2e + 35814eb commit 6724e74
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
42 changes: 41 additions & 1 deletion ThunderClient/EndpointTests.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -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": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ public ArrayList<Review> getRatings(@Valid @RequestParam int rating) {
return reviewService.getRatings(rating);
}

// READ (Search by customer Id)
@GetMapping("/customers/{id}")
public ArrayList<Review> searchReviewByCustomerId(@PathVariable long id) {
return reviewService.searchCustomerReviews(id);
}

// READ (Search by product Id)
@GetMapping("/products/{productId}")
public ArrayList<Review> searchReviewByProductId(@PathVariable long productId) {
return reviewService.searchProductReviews(productId);
}

// UPDATE.
@PutMapping("/{id}")
public ResponseEntity<Review> updateReview(@PathVariable long id, @RequestBody Review review) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/sg/com/smartinventory/entities/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -43,7 +43,7 @@ public ArrayList<Review> searchCustomerReviews(long customerId) {
@Override
public ArrayList<Review> searchProductReviews(long productId) {
Product product = productRepository.findById(productId).orElseThrow(() -> new ProductNotFoundException(productId));
List<Review> foundReviews = reviewRepository.findByProductId(productId);
List<Review> foundReviews = reviewRepository.findByProductId(product.getId());
return (ArrayList<Review>) foundReviews;
}

Expand Down

0 comments on commit 6724e74

Please sign in to comment.