Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET product reviews request with an invalid value of param "product_rating" the system returns all product reviews. #330

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public ResponseEntity<ProductReviewsAndRatingsWithPagination> getProductReviewsA
@RequestParam(name = "sort_attribute", defaultValue = "createdAt") final String sortAttribute,
@RequestParam(name = "sort_direction", defaultValue = "desc") final String sortDirection,
@RequestParam(name = "product_ratings", required = false) List<Integer> productRatings) {
log.info("Received the request to get reviews and ratings for the product with the productId = '{}' and with the next pagination and sorting attributes: pageNumber - {}, pageSize - {}, sort_attribute - {}, sort_direction - {}",
productId, pageNumber, pageSize, sortAttribute, sortDirection);
log.info("Received the request to get reviews and ratings for the product with the productId = '{}' and with the next pagination and sorting attributes: pageNumber - {}, pageSize - {}, sort_attribute - {}, sort_direction - {}, productRatings - {}",
productId, pageNumber, pageSize, sortAttribute, sortDirection, productRatings);
Pageable pageable = createPageableObject(pageNumber, pageSize, sortAttribute, sortDirection);
getReviewsRequestValidator.validate(pageNumber, pageSize, sortAttribute, sortDirection, productRatings);
ProductReviewsAndRatingsWithPagination reviewsPaginationDto = productReviewsProvider.getProductReviews(productId, pageable, productRatings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public void validate(final Integer pageNumber,

private StringBuilder validateProductRatingsParameter(final List<Integer> productRatings) {
final StringBuilder errorMessages = new StringBuilder();
if (productRatings == null) {
String errorMessage = String.format("product's rating is required. Allowed 'productRating' values are '%s'.", ALLOWED_PRODUCT_RATING_VALUES);
errorMessages.append(createErrorMessage(errorMessage));
}
if ((productRatings != null && productRatings.stream().anyMatch(Objects::isNull))
|| (productRatings != null && !ALLOWED_PRODUCT_RATING_VALUES.containsAll(productRatings))) {
String errorMessage = String.format("Some values of this product's rating list = '%s' are incorrect. Allowed 'productRating' values are '%s'.",
Expand Down
Loading