Skip to content

Commit

Permalink
Removing isEmpty dpendencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kadraman committed Jun 18, 2024
1 parent 760330b commit c7e3653
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ public Review saveReviewFromAdminReviewForm(AdminReviewForm adminReviewForm) thr
public Review newReviewFromNewReviewForm(NewReviewForm newReviewForm) {
Review rtmp = new Review();
Optional<User> optionalUser = userRepository.findById(newReviewForm.getUserId());
if (optionalUser.isEmpty()) throw new UserNotFoundException("Cannot find user for product review.");
if (!optionalUser.isPresent()) throw new UserNotFoundException("Cannot find user for product review.");
Optional<Product> optionalProduct = productRepository.findById(newReviewForm.getProductId());
if (optionalProduct.isEmpty()) throw new ProductNotFoundException("Cannot find product for product review");
if (!optionalProduct.isPresent()) throw new ProductNotFoundException("Cannot find product for product review");
rtmp.setProduct(optionalProduct.get());
rtmp.setUser(optionalUser.get());
rtmp.setComment(newReviewForm.getComment());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public String editReview(@PathVariable("id") UUID reviewId,
public String newReview(@RequestParam("pid") Optional<UUID> pid,
Model model, Principal principal) {
UUID productId = (pid.isPresent() ? pid.get() : null);
if (pid.isEmpty() || !productService.productExistsById(productId)) {
if (!pid.isPresent() || !productService.productExistsById(productId)) {
model.addAttribute("message", "The product id '" + productId.toString() + "' is invalid!");
model.addAttribute("alertClass", "alert-danger");
this.setModelDefaults(model, principal, "product-not-found");
Expand Down

0 comments on commit c7e3653

Please sign in to comment.