Commit 24bc3d38 authored by xkorenk's avatar xkorenk
Browse files

working ProductReview

parent 359f95e2
Pipeline #139084 passed with stages
in 2 minutes and 31 seconds
......@@ -116,10 +116,20 @@ public class ProductReviewController extends ControllerBase{
}
var dto = viewModel.toDto(getCurrentUser().getId());
productReviewService.create(dto);
var reviews = productReviewService.getAllByBottle(dto.getWineBottleId());
List<Long> users = reviews
.stream()
.map(x -> x.getUserId())
.distinct()
.collect(Collectors.toList());
if (!users.contains(dto.getUserId())){
productReviewService.create(dto);
viewModel.setSuccess(true);
} else {
viewModel.setExists(true);
}
initializeViewModel(viewModel);
viewModel.setSuccess(true);
return view(viewModel);
}
......
......@@ -32,6 +32,8 @@ public class ProductReviewUpsertViewModel extends ViewModelBase {
private boolean success;
private boolean exists;
/**
* grade of wine
*/
......
......@@ -9,10 +9,7 @@
<div class="container px-4 px-lg-5">
<main role="main" class="pb-3">
<h1>
<span>Review - Add</span>
<span th:text="${model.currentUser.id}"></span>
</h1>
<h1>Review - Add</h1>
<a class="btn btn-secondary" th:href="@{/productreview}">Back</a>
<div th:if="${model.success}">
......@@ -21,8 +18,14 @@
</div>
</div>
<div th:if="${model.exists}">
<div class="alert alert-success" role="alert">
This user already created review for this product
</div>
</div>
<form th:action="@{/productreview/add}" th:object="${model}" method="post">
<input type="hidden" th:field="*{userId}" th:value="*{currentUser.id}">
<input type="hidden" th:field="*{UserId}">
<div class="form-group">
<label th:for="*{wineBottleId}" th:value="*{wineBottleId}">Bottle</label>
<select class="form-control" th:field="*{wineBottleId}">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment