chore: update

This commit is contained in:
TakahashiNg
2026-05-12 02:27:26 +00:00
parent f7fe4b1518
commit f3d3a9f063
6 changed files with 24 additions and 121 deletions
@@ -58,6 +58,7 @@ public class CartService {
String cartId = UUID.randomUUID().toString(); String cartId = UUID.randomUUID().toString();
String redisKey = "cart:" + cartId; String redisKey = "cart:" + cartId;
String ownerId = response.readEntity(String.class);
hashCommands.hset( hashCommands.hset(
redisKey, redisKey,
@@ -65,7 +66,9 @@ public class CartService {
"_metadata_owner", "_metadata_owner",
userId != null ? userId : "GUEST", userId != null ? userId : "GUEST",
"_metadata_eatery", "_metadata_eatery",
eateryId.toString() eateryId.toString(),
"_metadata_ownerId",
ownerId
) )
); );
@@ -117,19 +120,36 @@ public class CartService {
@Name("quantity") long quantity @Name("quantity") long quantity
) { ) {
String key = "cart:" + cartId; String key = "cart:" + cartId;
String priceKey = "cart_prices:" + cartId;
UUID eateryId = UUID.fromString(hashCommands.hget(key, "_metadata_eatery")); String eateryIdStr = hashCommands.hget(key, "_metadata_eatery");
if (eateryIdStr == null) throw new RuntimeException("CartNotFound");
UUID eateryId = UUID.fromString(eateryIdStr);
return eateryController return eateryController
.checkMenuItemExists(eateryId, menuItemId) .checkMenuItemExists(eateryId, menuItemId)
.onItem() .onItem()
.transform(response -> { .transform(response -> {
if (response.getStatus() != Response.Status.OK.getStatusCode()) { if (response.getStatus() != Response.Status.OK.getStatusCode()) {
throw new RuntimeException("NotFoundEatery"); throw new RuntimeException("NotFoundMenuItemInEatery");
} }
Double menuItemPrice = response.readEntity(Double.class);
hashCommands.hincrby(key, menuItemId.toString(), quantity); hashCommands.hincrby(key, menuItemId.toString(), quantity);
hashCommands.hset(
priceKey,
menuItemId.toString(),
String.valueOf(menuItemPrice)
);
hashCommands.getDataSource().key().expire(key, Duration.ofDays(30)); hashCommands.getDataSource().key().expire(key, Duration.ofDays(30));
hashCommands
.getDataSource()
.key()
.expire(priceKey, Duration.ofDays(30));
try { try {
return getCart(cartId); return getCart(cartId);
-4
View File
@@ -129,10 +129,6 @@
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId> <artifactId>quarkus-rest-jackson</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker</artifactId> <artifactId>quarkus-container-image-docker</artifactId>
@@ -1,17 +0,0 @@
package com.drinkool.controllers;
import com.drinkool.Role;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.Response;
import java.util.UUID;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient(configKey = "account")
@Path(Role.Manager)
public interface AccountController {
@GET
@Path("/{id}")
public Response getManagerById(@PathParam("id") UUID id);
}
@@ -1,22 +0,0 @@
package com.drinkool.dtos;
import java.util.List;
import org.eclipse.microprofile.graphql.NonNull;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
public class OrderBill {
@NonNull
public List<OrderItem> items;
@NonNull
public Double totalAmount;
@NonNull
public String payQr;
}
@@ -1,20 +0,0 @@
package com.drinkool.dtos;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.eclipse.microprofile.graphql.NonNull;
@NoArgsConstructor
@AllArgsConstructor
public class OrderItem {
@NonNull
public UUID menuItemId;
@NonNull
public Integer quantity;
public Double price;
public Double subTotal;
}
@@ -2,11 +2,8 @@ package com.drinkool.services;
import com.drinkool.InternalValue; import com.drinkool.InternalValue;
import com.drinkool.Role; import com.drinkool.Role;
import com.drinkool.controllers.AccountController;
import com.drinkool.dtos.AddMenuItem; import com.drinkool.dtos.AddMenuItem;
import com.drinkool.dtos.DtoMapper; import com.drinkool.dtos.DtoMapper;
import com.drinkool.dtos.OrderBill;
import com.drinkool.dtos.OrderItem;
import com.drinkool.dtos.UpdateMenuItem; import com.drinkool.dtos.UpdateMenuItem;
import com.drinkool.entities.EateryEntity; import com.drinkool.entities.EateryEntity;
import com.drinkool.entities.MenuItemEntity; import com.drinkool.entities.MenuItemEntity;
@@ -17,20 +14,16 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam; import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.eclipse.microprofile.graphql.GraphQLApi; import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation; import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name; import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query; import org.eclipse.microprofile.graphql.Query;
import org.eclipse.microprofile.reactive.messaging.Incoming; import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.eclipse.microprofile.rest.client.inject.RestClient;
@ApplicationScoped @ApplicationScoped
@GraphQLApi @GraphQLApi
@@ -43,10 +36,6 @@ public class EateryService {
@Inject @Inject
HttpServerRequest request; HttpServerRequest request;
@Inject
@RestClient
AccountController accountController;
@GET @GET
@Path("/{id}") @Path("/{id}")
public Response checkEateryExists(@PathParam("id") UUID id) { public Response checkEateryExists(@PathParam("id") UUID id) {
@@ -58,7 +47,7 @@ public class EateryService {
.build(); .build();
} }
return Response.ok().build(); return Response.ok(eatery.ownerId.toString()).build();
} }
@GET @GET
@@ -164,47 +153,4 @@ public class EateryService {
return MenuItemEntity.list("eatery", eatery); return MenuItemEntity.list("eatery", eatery);
} }
@POST
@Path("/{id}")
public Response getSummary(
List<OrderItem> inputItems,
@PathParam("id") UUID eateryId
) {
List<OrderItem> details = new ArrayList<>();
double grandTotal = 0;
for (OrderItem input : inputItems) {
MenuItemEntity itemEntity = MenuItemEntity.find(
"id = ?1 and eatery.id = ?2",
input.menuItemId,
eateryId
).firstResult();
if (itemEntity != null) {
OrderItem detail = new OrderItem(
itemEntity.id,
input.quantity,
itemEntity.price,
itemEntity.price * input.quantity
);
details.add(detail);
grandTotal += detail.subTotal;
}
}
EateryEntity eatery = EateryEntity.findById(eateryId);
try (Response response = accountController.getManagerById(eatery.ownerId)) {
if (response.getStatus() == 200) {
Map<String, Object> data = response.readEntity(Map.class);
String bankNo = (String) data.get("bankAccount");
return Response.ok(new OrderBill(details, grandTotal, bankNo)).build();
}
return Response.serverError().entity(response.getEntity()).build();
}
}
} }