fix: add cart service (#46)
Release package / release (push) Successful in 30m35s

Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com>
Reviewed-on: #46
This commit was merged in pull request #46.
This commit is contained in:
2026-05-07 08:43:19 +00:00
parent 77d34d7a02
commit bb828d7532
29 changed files with 1566 additions and 53 deletions
+14
View File
@@ -28,6 +28,7 @@
<quarkus.platform.version>3.32.4</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.5.4</surefire-plugin.version>
<org.projectlombok.version>1.18.46</org.projectlombok.version>
</properties>
<dependencyManagement>
@@ -48,6 +49,12 @@
<artifactId>jose4j</artifactId>
<version>0.9.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security</artifactId>
@@ -106,6 +113,13 @@
<version>${compiler-plugin.version}</version>
<configuration>
<parameters>true</parameters>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
@@ -0,0 +1,27 @@
package com.drinkool.controller;
import com.drinkool.lib.dtos.GraphqlDto;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;
import lombok.Getter;
import org.eclipse.microprofile.config.inject.ConfigProperty;
@Path("/api/cart")
@Getter
public class CartController extends GraphqlBase {
@ConfigProperty(name = "quarkus.smallrye-graphql-client.cart.url")
String graphqlUrl;
@POST
@Path("/graphql")
public Response forward(
GraphqlDto gqlRequest,
@Context HttpHeaders httpHeaders
) {
return send(gqlRequest, httpHeaders);
}
}
@@ -1,16 +1,12 @@
package com.drinkool.controller;
import com.drinkool.InternalValue;
import com.drinkool.Url;
import com.drinkool.enums.SortBy;
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.DynamicGraphQLClientBuilder;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import jakarta.json.bind.Jsonb;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
@@ -19,20 +15,18 @@ import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.UUID;
import lombok.Getter;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/api/eatery")
public class EateryController {
@Getter
public class EateryController extends GraphqlBase {
@ConfigProperty(name = "quarkus.smallrye-graphql-client.eatery.url")
String eateryUrl;
@Inject
Jsonb jsonb;
String graphqlUrl;
@Inject
@RestClient
@@ -40,7 +34,7 @@ public class EateryController {
@GET
@Path(Url.Review + "/{eateryId}")
Uni<Response> getReviewsByEatery(
public Uni<Response> getReviewsByEatery(
@PathParam("eateryId") UUID eateryId,
@QueryParam("sort") @DefaultValue("LATEST") SortBy sortBy
) {
@@ -49,7 +43,7 @@ public class EateryController {
@POST
@Path(Url.Review)
Uni<Response> receiveReview(SendReview input) {
public Uni<Response> receiveReview(SendReview input) {
return reviewService.receiveReview(input);
}
@@ -59,41 +53,6 @@ public class EateryController {
GraphqlDto gqlRequest,
@Context HttpHeaders httpHeaders
) {
DynamicGraphQLClientBuilder builder =
DynamicGraphQLClientBuilder.newBuilder().url(eateryUrl);
httpHeaders
.getRequestHeaders()
.forEach((name, values) -> {
String headerName = name.toLowerCase();
if (headerName.startsWith(InternalValue.headerId.toLowerCase())) {
if (!values.isEmpty()) {
builder.header(name, values.get(0));
}
}
});
try (DynamicGraphQLClient tempClient = builder.build()) {
io.smallrye.graphql.client.Response response = tempClient.executeSync(
gqlRequest.query,
gqlRequest.variables
);
if (response.hasError()) {
return Response.status(400)
.entity(jsonb.toJson(response.getErrors()))
.build();
}
return Response.ok(jsonb.toJson(response.getData()))
.type(MediaType.APPLICATION_JSON)
.build();
} catch (Exception e) {
e.printStackTrace();
return Response.serverError()
.entity("Lỗi kết nối tới service Eatery")
.build();
}
return send(gqlRequest, httpHeaders);
}
}
@@ -0,0 +1,56 @@
package com.drinkool.controller;
import com.drinkool.InternalValue;
import com.drinkool.lib.dtos.GraphqlDto;
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClientBuilder;
import jakarta.inject.Inject;
import jakarta.json.bind.Jsonb;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
public abstract class GraphqlBase {
@Inject
Jsonb jsonb;
public abstract String getGraphqlUrl();
public Response send(GraphqlDto gqlRequest, HttpHeaders httpHeaders) {
DynamicGraphQLClientBuilder builder =
DynamicGraphQLClientBuilder.newBuilder().url(getGraphqlUrl());
httpHeaders
.getRequestHeaders()
.forEach((name, values) -> {
String headerName = name.toLowerCase();
if (headerName.startsWith(InternalValue.headerId.toLowerCase())) {
if (!values.isEmpty()) {
builder.header(name, values.get(0));
}
}
});
try (DynamicGraphQLClient tempClient = builder.build()) {
io.smallrye.graphql.client.Response response = tempClient.executeSync(
gqlRequest.query,
gqlRequest.variables
);
if (response.hasError()) {
return Response.status(400)
.entity(jsonb.toJson(response.getErrors()))
.build();
}
return Response.ok(jsonb.toJson(response.getData()))
.type(MediaType.APPLICATION_JSON)
.build();
} catch (Exception e) {
e.printStackTrace();
return Response.serverError().entity("Lỗi kết nối tới service").build();
}
}
}
@@ -17,4 +17,5 @@ quarkus.rest-client.account.url=http://account-service
quarkus.rest-client.eatery.url=http://eatery-service
# GraphQL Client
quarkus.smallrye-graphql-client.eatery.url=http://eatery-service/graphql
quarkus.smallrye-graphql-client.eatery.url=http://eatery-service/graphql
quarkus.smallrye-graphql-client.cart.url=http://cart-service/graphql
@@ -5,4 +5,4 @@ quarkus.http.host=0.0.0.0
gateway.jwt.secret=1uZk07Hqu1316z9YqrcSGPTTJDhMWU1ZhFSLBrDQvmU=
# App configuration
quarkus.rest-client.account.url=http://account-service:8080
quarkus.rest-client.account.url=http://account-service:8080