Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e610111e66 | |||
| d104f8b210 |
@@ -1,3 +1,10 @@
|
|||||||
|
## [1.5.20](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.19...v1.5.20) (2026-05-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* menu items CRUD ([#44](https://git.demonkernel.io.vn/FoodSurf/backend/issues/44)) ([43600fc](https://git.demonkernel.io.vn/FoodSurf/backend/commit/43600fc8cfa2cd93e1d33ee855a2934a49f8d663))
|
||||||
|
|
||||||
## [1.5.19](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.18...v1.5.19) (2026-05-05)
|
## [1.5.19](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.18...v1.5.19) (2026-05-05)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.drinkool</groupId>
|
<groupId>com.drinkool</groupId>
|
||||||
<artifactId>drinkool</artifactId>
|
<artifactId>drinkool</artifactId>
|
||||||
<version>1.5.19</version>
|
<version>1.5.20</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.drinkool.services;
|
|||||||
import com.drinkool.*;
|
import com.drinkool.*;
|
||||||
import com.drinkool.entities.CustomerEntity;
|
import com.drinkool.entities.CustomerEntity;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
|
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.drinkool.*;
|
|||||||
import com.drinkool.entities.ManagerEntity;
|
import com.drinkool.entities.ManagerEntity;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
import com.drinkool.lib.dtos.event.ManagerCreate;
|
import com.drinkool.lib.dtos.event.ManagerCreate;
|
||||||
|
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import static io.restassured.RestAssured.*;
|
|||||||
|
|
||||||
import com.drinkool.*;
|
import com.drinkool.*;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import static org.hamcrest.CoreMatchers.*;
|
|||||||
|
|
||||||
import com.drinkool.*;
|
import com.drinkool.*;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
import com.drinkool.*;
|
import com.drinkool.*;
|
||||||
import com.drinkool.entities.CustomerEntity;
|
import com.drinkool.entities.CustomerEntity;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
import com.drinkool.*;
|
import com.drinkool.*;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
|
|
||||||
import io.quarkus.test.common.QuarkusTestResource;
|
import io.quarkus.test.common.QuarkusTestResource;
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.quarkus.test.kafka.*;
|
import io.quarkus.test.kafka.*;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.drinkool</groupId>
|
<groupId>com.drinkool</groupId>
|
||||||
<artifactId>drinkool</artifactId>
|
<artifactId>drinkool</artifactId>
|
||||||
<version>1.5.19</version>
|
<version>1.5.20</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.drinkool.dtos;
|
package com.drinkool.dtos;
|
||||||
|
|
||||||
import com.drinkool.entities.MenuItemEntity;
|
import com.drinkool.entities.MenuItemEntity;
|
||||||
|
import com.drinkool.entities.ReviewEntity;
|
||||||
|
import com.drinkool.lib.dtos.SendReview;
|
||||||
import org.mapstruct.BeanMapping;
|
import org.mapstruct.BeanMapping;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.MappingTarget;
|
import org.mapstruct.MappingTarget;
|
||||||
@@ -15,4 +17,6 @@ public interface DtoMapper {
|
|||||||
UpdateMenuItem input,
|
UpdateMenuItem input,
|
||||||
@MappingTarget MenuItemEntity entity
|
@MappingTarget MenuItemEntity entity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ReviewEntity toReviewEntity(SendReview source);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,34 @@
|
|||||||
package com.drinkool.entities;
|
package com.drinkool.entities;
|
||||||
|
|
||||||
import com.drinkool.lib.models.ReviewModel;
|
import com.drinkool.interfaces.ReviewInterface;
|
||||||
|
import com.drinkool.lib.entities.BaseEntity;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table(name = "reviews")
|
@Table(name = "reviews")
|
||||||
public class ReviewEntity extends ReviewModel {
|
public class ReviewEntity extends BaseEntity implements ReviewInterface {
|
||||||
|
|
||||||
public UUID reviewerId;
|
public UUID reviewerId;
|
||||||
|
|
||||||
public UUID eateryId;
|
public UUID eateryId;
|
||||||
|
|
||||||
private ReviewEntity(ReviewModel input) {
|
public Integer rating;
|
||||||
super(input);
|
|
||||||
|
public String comment;
|
||||||
|
|
||||||
|
public void setRating(Integer score) {
|
||||||
|
if (score < 1 || score > 5) {
|
||||||
|
throw new IllegalArgumentException("InvalidRatingValue");
|
||||||
}
|
}
|
||||||
|
this.rating = score;
|
||||||
@Transactional
|
|
||||||
public static ReviewEntity create(
|
|
||||||
UUID reviewerId,
|
|
||||||
UUID eateryId,
|
|
||||||
ReviewModel reviewInput
|
|
||||||
) {
|
|
||||||
ReviewEntity review = new ReviewEntity(reviewInput);
|
|
||||||
|
|
||||||
review.reviewerId = reviewerId;
|
|
||||||
review.eateryId = eateryId;
|
|
||||||
|
|
||||||
review.persist();
|
|
||||||
|
|
||||||
return review;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,71 @@
|
|||||||
package com.drinkool.services;
|
package com.drinkool.services;
|
||||||
|
|
||||||
|
import com.drinkool.InternalValue;
|
||||||
|
import com.drinkool.Role;
|
||||||
|
import com.drinkool.Url;
|
||||||
|
import com.drinkool.dtos.DtoMapper;
|
||||||
import com.drinkool.entities.ReviewEntity;
|
import com.drinkool.entities.ReviewEntity;
|
||||||
|
import com.drinkool.enums.SortBy;
|
||||||
import com.drinkool.lib.dtos.SendReview;
|
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.transaction.Transactional;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.DefaultValue;
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.POST;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.PathParam;
|
||||||
|
import jakarta.ws.rs.QueryParam;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Path("/api/review")
|
@Path(Url.Review)
|
||||||
public class ReviewService {
|
public class ReviewService {
|
||||||
|
|
||||||
@POST
|
@Inject
|
||||||
@Path("/create")
|
HttpServerRequest request;
|
||||||
@Transactional
|
|
||||||
public Response create(SendReview input) {
|
|
||||||
ReviewEntity.create(input.reviewerId, input.orderId, input.review);
|
|
||||||
|
|
||||||
return Response.status(201).build();
|
@Inject
|
||||||
|
DtoMapper dtoMapper;
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Transactional
|
||||||
|
@Path("/{eateryId}")
|
||||||
|
public Response getReviewsByEatery(
|
||||||
|
@PathParam("eateryId") UUID eateryId,
|
||||||
|
@QueryParam("sort") @DefaultValue("LATEST") SortBy sortBy
|
||||||
|
) {
|
||||||
|
Sort sort = switch (sortBy) {
|
||||||
|
case LATEST -> Sort.descending("createDate");
|
||||||
|
case OLDEST -> Sort.ascending("createDate");
|
||||||
|
case HIGHEST -> Sort.descending("rating");
|
||||||
|
case LOWEST -> Sort.ascending("rating");
|
||||||
|
};
|
||||||
|
|
||||||
|
return Response.ok()
|
||||||
|
.entity(ReviewEntity.find("eateryId = ?1", sort, eateryId).list())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
|
||||||
|
return Response.status(Response.Status.CREATED).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(e.getMessage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,34 @@
|
|||||||
package com.drinkool.entities;
|
package com.drinkool.entities;
|
||||||
|
|
||||||
import com.drinkool.lib.models.ReviewModel;
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import net.datafaker.Faker;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
public class ReviewEntityTest {
|
public class ReviewEntityTest {
|
||||||
|
|
||||||
|
private final Faker faker = new Faker();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
public void testCreateReview() {
|
public void testCreateReview() {
|
||||||
// 1. Chuẩn bị dữ liệu (Arrange)
|
|
||||||
UUID testReviewerId = UUID.randomUUID();
|
UUID testReviewerId = UUID.randomUUID();
|
||||||
UUID testEateryId = UUID.randomUUID();
|
UUID testEateryId = UUID.randomUUID();
|
||||||
|
String comment = faker.famousLastWords().lastWords();
|
||||||
|
int rating = faker.random().nextInt(1, 5);
|
||||||
|
|
||||||
// Truyền trực tiếp rating và comment vào constructor của ReviewModel
|
ReviewEntity savedReview = new ReviewEntity(
|
||||||
ReviewModel inputModel = new ReviewModel(5, "Món ăn tuyệt vời!");
|
|
||||||
|
|
||||||
// 2. Thực thi (Act)
|
|
||||||
ReviewEntity savedReview = ReviewEntity.create(
|
|
||||||
testReviewerId,
|
testReviewerId,
|
||||||
testEateryId,
|
testEateryId,
|
||||||
inputModel
|
rating,
|
||||||
|
comment
|
||||||
);
|
);
|
||||||
|
|
||||||
|
savedReview.persist();
|
||||||
|
|
||||||
// 3. Kiểm chứng (Assert)
|
// 3. Kiểm chứng (Assert)
|
||||||
Assertions.assertNotNull(
|
Assertions.assertNotNull(
|
||||||
savedReview,
|
savedReview,
|
||||||
@@ -42,12 +44,8 @@ public class ReviewEntityTest {
|
|||||||
savedReview.eateryId,
|
savedReview.eateryId,
|
||||||
"Eatery ID không khớp"
|
"Eatery ID không khớp"
|
||||||
);
|
);
|
||||||
Assertions.assertEquals(5, savedReview.rating, "Rating không khớp");
|
Assertions.assertEquals(rating, savedReview.rating, "Rating không khớp");
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(comment, savedReview.comment, "Comment không khớp");
|
||||||
"Món ăn tuyệt vời!",
|
|
||||||
savedReview.comment,
|
|
||||||
"Comment không khớp"
|
|
||||||
);
|
|
||||||
|
|
||||||
Assertions.assertNotNull(
|
Assertions.assertNotNull(
|
||||||
savedReview.id,
|
savedReview.id,
|
||||||
|
|||||||
@@ -1,43 +1,109 @@
|
|||||||
package com.drinkool.services;
|
package com.drinkool.services;
|
||||||
|
|
||||||
import static io.restassured.RestAssured.given;
|
import static io.restassured.RestAssured.given;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import com.drinkool.InternalValue;
|
||||||
|
import com.drinkool.Role;
|
||||||
|
import com.drinkool.Url;
|
||||||
|
import com.drinkool.entities.EateryEntity;
|
||||||
|
import com.drinkool.entities.MenuItemEntity;
|
||||||
import com.drinkool.entities.ReviewEntity;
|
import com.drinkool.entities.ReviewEntity;
|
||||||
import com.drinkool.lib.dtos.SendReview;
|
import com.drinkool.lib.dtos.SendReview;
|
||||||
import com.drinkool.lib.models.ReviewModel;
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import java.util.Random;
|
import jakarta.transaction.Transactional;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import net.datafaker.Faker;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
public class ReviewServiceTest {
|
public class ReviewServiceTest {
|
||||||
|
|
||||||
|
private final Faker faker = new Faker();
|
||||||
|
|
||||||
|
private UUID savedEateryId;
|
||||||
|
private String savedEateryName;
|
||||||
|
private UUID savedOwnerId = UUID.randomUUID();
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
@Transactional
|
||||||
|
void setup() {
|
||||||
|
ReviewEntity.deleteAll();
|
||||||
|
MenuItemEntity.deleteAll();
|
||||||
|
EateryEntity.deleteAll();
|
||||||
|
|
||||||
|
savedEateryName = faker.restaurant().name();
|
||||||
|
|
||||||
|
EateryEntity eatery = new EateryEntity();
|
||||||
|
eatery = eatery.create(savedOwnerId, savedEateryName);
|
||||||
|
savedEateryId = eatery.id;
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
ReviewEntity entity = new ReviewEntity(
|
||||||
|
UUID.randomUUID(),
|
||||||
|
savedEateryId,
|
||||||
|
faker.random().nextInt(1, 5),
|
||||||
|
faker.famousLastWords().lastWords()
|
||||||
|
);
|
||||||
|
|
||||||
|
entity.persist();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void receiveReview() {
|
void receiveReview_Success() {
|
||||||
Random random = new Random();
|
|
||||||
|
|
||||||
UUID reviewerId = UUID.randomUUID();
|
UUID reviewerId = UUID.randomUUID();
|
||||||
UUID orderId = UUID.randomUUID();
|
UUID eateryId = UUID.randomUUID();
|
||||||
String comment = UUID.randomUUID().toString();
|
String comment = faker.famousLastWords().lastWords();
|
||||||
int rating = random.nextInt();
|
int rating = faker.random().nextInt(1, 5);
|
||||||
|
|
||||||
SendReview input = new SendReview();
|
SendReview input = new SendReview(reviewerId, eateryId, rating, comment);
|
||||||
input.reviewerId = reviewerId;
|
|
||||||
input.orderId = orderId;
|
|
||||||
ReviewModel reviewModel = new ReviewModel(rating, comment);
|
|
||||||
input.review = reviewModel;
|
|
||||||
|
|
||||||
given()
|
given()
|
||||||
|
.header(InternalValue.role, Role.Customer)
|
||||||
|
.header(InternalValue.userId, reviewerId)
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
.body(input)
|
.body(input)
|
||||||
.when()
|
.when()
|
||||||
.post("/api/review/create")
|
.post(Url.Review)
|
||||||
.then()
|
.then()
|
||||||
.statusCode(201);
|
.statusCode(Response.Status.CREATED.getStatusCode());
|
||||||
|
|
||||||
assertEquals(1, ReviewEntity.find("reviewerId", reviewerId).count());
|
assertEquals(1, ReviewEntity.find("reviewerId", reviewerId).count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void receiveReview_FailedDueToInvalidRating() {
|
||||||
|
UUID reviewerId = UUID.randomUUID();
|
||||||
|
UUID eateryId = UUID.randomUUID();
|
||||||
|
String comment = faker.famousLastWords().lastWords();
|
||||||
|
int rating = faker.random().nextInt(6, 10);
|
||||||
|
|
||||||
|
SendReview input = new SendReview(reviewerId, eateryId, rating, comment);
|
||||||
|
|
||||||
|
given()
|
||||||
|
.header(InternalValue.role, Role.Customer)
|
||||||
|
.header(InternalValue.userId, UUID.randomUUID())
|
||||||
|
.contentType(ContentType.JSON)
|
||||||
|
.body(input)
|
||||||
|
.when()
|
||||||
|
.post(Url.Review)
|
||||||
|
.then()
|
||||||
|
.contentType(ContentType.TEXT)
|
||||||
|
.body(is("InvalidRatingValue"))
|
||||||
|
.statusCode(Response.Status.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetReviews_DefaultLatest() {
|
||||||
|
given()
|
||||||
|
.when()
|
||||||
|
.get(Url.Review + '/' + savedEateryId.toString())
|
||||||
|
.then()
|
||||||
|
.statusCode(Response.Status.OK.getStatusCode())
|
||||||
|
.contentType(ContentType.JSON);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.drinkool</groupId>
|
<groupId>com.drinkool</groupId>
|
||||||
<artifactId>drinkool</artifactId>
|
<artifactId>drinkool</artifactId>
|
||||||
<version>1.5.19</version>
|
<version>1.5.20</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
package com.drinkool.controller;
|
package com.drinkool.controller;
|
||||||
|
|
||||||
import com.drinkool.InternalValue;
|
import com.drinkool.InternalValue;
|
||||||
|
import com.drinkool.Url;
|
||||||
|
import com.drinkool.enums.SortBy;
|
||||||
import com.drinkool.lib.dtos.GraphqlDto;
|
import com.drinkool.lib.dtos.GraphqlDto;
|
||||||
|
import com.drinkool.lib.dtos.SendReview;
|
||||||
|
import com.drinkool.services.ReviewService;
|
||||||
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;
|
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;
|
||||||
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClientBuilder;
|
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClientBuilder;
|
||||||
|
import io.smallrye.mutiny.Uni;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.json.bind.Jsonb;
|
import jakarta.json.bind.Jsonb;
|
||||||
|
import jakarta.ws.rs.DefaultValue;
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.POST;
|
import jakarta.ws.rs.POST;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.PathParam;
|
||||||
|
import jakarta.ws.rs.QueryParam;
|
||||||
import jakarta.ws.rs.core.Context;
|
import jakarta.ws.rs.core.Context;
|
||||||
import jakarta.ws.rs.core.HttpHeaders;
|
import jakarta.ws.rs.core.HttpHeaders;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.UUID;
|
||||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
|
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||||
|
|
||||||
@Path("/api/eatery")
|
@Path("/api/eatery")
|
||||||
public class EateryController {
|
public class EateryController {
|
||||||
@@ -24,6 +34,25 @@ public class EateryController {
|
|||||||
@Inject
|
@Inject
|
||||||
Jsonb jsonb;
|
Jsonb jsonb;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@RestClient
|
||||||
|
ReviewService reviewService;
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path(Url.Review + "/{eateryId}")
|
||||||
|
Uni<Response> getReviewsByEatery(
|
||||||
|
@PathParam("eateryId") UUID eateryId,
|
||||||
|
@QueryParam("sort") @DefaultValue("LATEST") SortBy sortBy
|
||||||
|
) {
|
||||||
|
return reviewService.getReviewsByEatery(eateryId, sortBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path(Url.Review)
|
||||||
|
Uni<Response> receiveReview(SendReview input) {
|
||||||
|
return reviewService.receiveReview(input);
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/graphql")
|
@Path("/graphql")
|
||||||
public Response forward(
|
public Response forward(
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.drinkool.services;
|
|||||||
|
|
||||||
import com.drinkool.Url;
|
import com.drinkool.Url;
|
||||||
import com.drinkool.lib.dtos.SmsOtp;
|
import com.drinkool.lib.dtos.SmsOtp;
|
||||||
|
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import jakarta.ws.rs.POST;
|
import jakarta.ws.rs.POST;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.drinkool.InternalValue;
|
|||||||
import com.drinkool.Role;
|
import com.drinkool.Role;
|
||||||
import com.drinkool.Url;
|
import com.drinkool.Url;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
|
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.drinkool.InternalValue;
|
|||||||
import com.drinkool.Role;
|
import com.drinkool.Role;
|
||||||
import com.drinkool.Url;
|
import com.drinkool.Url;
|
||||||
import com.drinkool.lib.dtos.*;
|
import com.drinkool.lib.dtos.*;
|
||||||
|
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.drinkool.services;
|
||||||
|
|
||||||
|
import com.drinkool.Url;
|
||||||
|
import com.drinkool.enums.SortBy;
|
||||||
|
import com.drinkool.lib.dtos.SendReview;
|
||||||
|
|
||||||
|
import io.smallrye.mutiny.Uni;
|
||||||
|
import jakarta.ws.rs.DefaultValue;
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.POST;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.PathParam;
|
||||||
|
import jakarta.ws.rs.QueryParam;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
||||||
|
|
||||||
|
@RegisterRestClient(configKey = "eatery")
|
||||||
|
@Path(Url.Review)
|
||||||
|
public interface ReviewService {
|
||||||
|
@GET
|
||||||
|
@Path("/{eateryId}")
|
||||||
|
public Uni<Response> getReviewsByEatery(
|
||||||
|
@PathParam("eateryId") UUID eateryId,
|
||||||
|
@QueryParam("sort") @DefaultValue("LATEST") SortBy sortBy
|
||||||
|
);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public Uni<Response> receiveReview(SendReview input);
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ quarkus.native.additional-build-args=--future-defaults=all
|
|||||||
|
|
||||||
# Rest Client
|
# Rest Client
|
||||||
quarkus.rest-client.account.url=http://account-service
|
quarkus.rest-client.account.url=http://account-service
|
||||||
|
quarkus.rest-client.eatery.url=http://eatery-service
|
||||||
|
|
||||||
# GraphQL Client
|
# GraphQL Client
|
||||||
quarkus.smallrye-graphql-client.eatery.url=http://eatery-service/graphql
|
quarkus.smallrye-graphql-client.eatery.url=http://eatery-service/graphql
|
||||||
@@ -14,7 +14,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: account-pod
|
- name: account-pod
|
||||||
image: git.demonkernel.io.vn/foodsurf/account-service:1.5.19
|
image: git.demonkernel.io.vn/foodsurf/account-service:1.5.20
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: eatery-pod
|
- name: eatery-pod
|
||||||
image: git.demonkernel.io.vn/foodsurf/eatery-service:1.5.19
|
image: git.demonkernel.io.vn/foodsurf/eatery-service:1.5.20
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: gateway-pod
|
- name: gateway-pod
|
||||||
image: git.demonkernel.io.vn/foodsurf/gateway-service:1.5.19
|
image: git.demonkernel.io.vn/foodsurf/gateway-service:1.5.20
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|||||||
+38
-3
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project
|
<project
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.drinkool</groupId>
|
<groupId>com.drinkool</groupId>
|
||||||
<artifactId>drinkool</artifactId>
|
<artifactId>drinkool</artifactId>
|
||||||
<version>1.5.19</version>
|
<version>1.5.20</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
<maven.compiler.source>25</maven.compiler.source>
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
<maven.compiler.target>25</maven.compiler.target>
|
<maven.compiler.target>25</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<org.projectlombok.version>1.18.46</org.projectlombok.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -41,7 +42,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.46</version>
|
<version>${org.projectlombok.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -67,4 +68,38 @@
|
|||||||
<artifactId>quarkus-smallrye-graphql</artifactId>
|
<artifactId>quarkus-smallrye-graphql</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<parameters>true</parameters>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${org.projectlombok.version}</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.smallrye</groupId>
|
||||||
|
<artifactId>jandex-maven-plugin</artifactId>
|
||||||
|
<version>3.2.7</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-index</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jandex</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -9,4 +9,5 @@ public class Url {
|
|||||||
public static final String SmsOtp = "/sms_otp";
|
public static final String SmsOtp = "/sms_otp";
|
||||||
public static final String Me = "/me";
|
public static final String Me = "/me";
|
||||||
public static final String Logout = "/logout";
|
public static final String Logout = "/logout";
|
||||||
|
public static final String Review = "/review";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.drinkool.enums;
|
||||||
|
|
||||||
|
public enum SortBy {
|
||||||
|
LATEST,
|
||||||
|
OLDEST,
|
||||||
|
HIGHEST,
|
||||||
|
LOWEST,
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.drinkool.interfaces;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface ReviewInterface {
|
||||||
|
UUID getReviewerId();
|
||||||
|
void setReviewerId(UUID x);
|
||||||
|
|
||||||
|
UUID getEateryId();
|
||||||
|
void setEateryId(UUID x);
|
||||||
|
|
||||||
|
Integer getRating();
|
||||||
|
void setRating(Integer x);
|
||||||
|
|
||||||
|
String getComment();
|
||||||
|
void setComment(String x);
|
||||||
|
}
|
||||||
@@ -1,11 +1,26 @@
|
|||||||
package com.drinkool.lib.dtos;
|
package com.drinkool.lib.dtos;
|
||||||
|
|
||||||
import com.drinkool.lib.models.ReviewModel;
|
import com.drinkool.interfaces.ReviewInterface;
|
||||||
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
public class SendReview {
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RegisterForReflection
|
||||||
|
public class SendReview implements ReviewInterface {
|
||||||
|
|
||||||
public UUID reviewerId;
|
private UUID reviewerId;
|
||||||
public UUID orderId;
|
private UUID eateryId;
|
||||||
public ReviewModel review;
|
private Integer rating;
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
public void setReviewerId(UUID x) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
|||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.MappedSuperclass;
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public class BaseEntity extends PanacheEntityBase {
|
public class BaseEntity extends PanacheEntityBase {
|
||||||
@@ -12,4 +15,10 @@ public class BaseEntity extends PanacheEntityBase {
|
|||||||
@jakarta.persistence.Id
|
@jakarta.persistence.Id
|
||||||
@GeneratedValue(strategy = GenerationType.UUID)
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
public UUID id;
|
public UUID id;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
public LocalDateTime createDate;
|
||||||
|
|
||||||
|
@UpdateTimestamp
|
||||||
|
public LocalDateTime updateDate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.drinkool.lib.models;
|
|
||||||
|
|
||||||
import com.drinkool.lib.entities.BaseEntity;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@MappedSuperclass
|
|
||||||
public class ReviewModel extends BaseEntity {
|
|
||||||
|
|
||||||
@Column
|
|
||||||
public int rating;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
public String comment;
|
|
||||||
|
|
||||||
public ReviewModel(int rating, String comment) {
|
|
||||||
this.rating = rating;
|
|
||||||
this.comment = comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReviewModel() {}
|
|
||||||
|
|
||||||
public ReviewModel(ReviewModel input) {
|
|
||||||
this(input.rating, input.comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@org.hibernate.annotations.CreationTimestamp
|
|
||||||
@Column(name = "review_date", updatable = false)
|
|
||||||
public LocalDateTime reviewDate;
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.drinkool</groupId>
|
<groupId>com.drinkool</groupId>
|
||||||
<artifactId>drinkool</artifactId>
|
<artifactId>drinkool</artifactId>
|
||||||
<version>1.5.19</version>
|
<version>1.5.20</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>25</maven.compiler.source>
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
|
|||||||
Reference in New Issue
Block a user