This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package com.drinkool.services;
|
||||
|
||||
import com.drinkool.InternalValue;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.dtos.DtoMapper;
|
||||
import com.drinkool.entities.ReviewEntity;
|
||||
import com.drinkool.enums.SortBy;
|
||||
import com.drinkool.lib.dtos.SendReview;
|
||||
import io.quarkus.panache.common.Sort;
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
@@ -19,6 +23,9 @@ import java.util.UUID;
|
||||
@Path("/api/review")
|
||||
public class ReviewService {
|
||||
|
||||
@Inject
|
||||
HttpServerRequest request;
|
||||
|
||||
@Inject
|
||||
DtoMapper dtoMapper;
|
||||
|
||||
@@ -42,10 +49,14 @@ public class ReviewService {
|
||||
}
|
||||
|
||||
@POST
|
||||
@RolesAllowed(Role.Customer)
|
||||
@Transactional
|
||||
public Response receiveReview(SendReview input) {
|
||||
UUID reviewerId = UUID.fromString(request.getHeader(InternalValue.userId));
|
||||
|
||||
try {
|
||||
ReviewEntity entity = dtoMapper.toReviewEntity(input);
|
||||
entity.setReviewerId(reviewerId);
|
||||
|
||||
entity.persist();
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.drinkool.InternalValue;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.entities.EateryEntity;
|
||||
import com.drinkool.entities.ReviewEntity;
|
||||
import com.drinkool.lib.dtos.SendReview;
|
||||
@@ -91,6 +93,8 @@ public class ReviewServiceTest {
|
||||
@Test
|
||||
public void testGetReviews_DefaultLatest() {
|
||||
given()
|
||||
.header(InternalValue.role, Role.Customer)
|
||||
.header(InternalValue.userId, UUID.randomUUID())
|
||||
.when()
|
||||
.get("/api/review/" + savedEateryId.toString())
|
||||
.then()
|
||||
|
||||
@@ -19,4 +19,8 @@ public class SendReview implements ReviewInterface {
|
||||
private UUID eateryId;
|
||||
private Integer rating;
|
||||
private String comment;
|
||||
|
||||
public void setReviewerId(UUID x) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user