chore: update
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.drinkool.controllers;
|
package com.drinkool.controllers;
|
||||||
|
|
||||||
import com.drinkool.Role;
|
import com.drinkool.Role;
|
||||||
import io.smallrye.mutiny.Uni;
|
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.PathParam;
|
import jakarta.ws.rs.PathParam;
|
||||||
@@ -15,7 +14,7 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
|||||||
public interface ManagerController {
|
public interface ManagerController {
|
||||||
@GET
|
@GET
|
||||||
@Path(Role.Manager + "/{id}/payment-qr")
|
@Path(Role.Manager + "/{id}/payment-qr")
|
||||||
public Uni<Response> getManagerPaymentQr(
|
public Response getManagerPaymentQr(
|
||||||
@PathParam("id") UUID id,
|
@PathParam("id") UUID id,
|
||||||
@QueryParam("amount") Long amount,
|
@QueryParam("amount") Long amount,
|
||||||
@QueryParam("cartId") String cartId
|
@QueryParam("cartId") String cartId
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ public class Cart {
|
|||||||
public UUID userId;
|
public UUID userId;
|
||||||
public UUID eateryId;
|
public UUID eateryId;
|
||||||
public List<CartItem> items;
|
public List<CartItem> items;
|
||||||
|
public long totalAmount;
|
||||||
|
public String paymentQrUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,7 @@ public class CartItem {
|
|||||||
|
|
||||||
public String productId;
|
public String productId;
|
||||||
public Integer quantity;
|
public Integer quantity;
|
||||||
|
|
||||||
|
public Double priceAtTimeOfAdding;
|
||||||
|
public Double subTotal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.drinkool.services;
|
|||||||
|
|
||||||
import com.drinkool.InternalValue;
|
import com.drinkool.InternalValue;
|
||||||
import com.drinkool.controllers.EateryController;
|
import com.drinkool.controllers.EateryController;
|
||||||
|
import com.drinkool.controllers.ManagerController;
|
||||||
import com.drinkool.dtos.Cart;
|
import com.drinkool.dtos.Cart;
|
||||||
import com.drinkool.dtos.CartItem;
|
import com.drinkool.dtos.CartItem;
|
||||||
import io.quarkus.redis.datasource.RedisDataSource;
|
import io.quarkus.redis.datasource.RedisDataSource;
|
||||||
@@ -35,6 +36,10 @@ public class CartService {
|
|||||||
@RestClient
|
@RestClient
|
||||||
EateryController eateryController;
|
EateryController eateryController;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@RestClient
|
||||||
|
ManagerController managerController;
|
||||||
|
|
||||||
private final HashCommands<String, String, String> hashCommands;
|
private final HashCommands<String, String, String> hashCommands;
|
||||||
private final ValueCommands<String, String> valueCommands;
|
private final ValueCommands<String, String> valueCommands;
|
||||||
|
|
||||||
@@ -67,7 +72,7 @@ public class CartService {
|
|||||||
userId != null ? userId : "GUEST",
|
userId != null ? userId : "GUEST",
|
||||||
"_metadata_eatery",
|
"_metadata_eatery",
|
||||||
eateryId.toString(),
|
eateryId.toString(),
|
||||||
"_metadata_ownerId",
|
"_metadata_eateryManagerId",
|
||||||
ownerId
|
ownerId
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -90,27 +95,56 @@ public class CartService {
|
|||||||
@Query("getCart")
|
@Query("getCart")
|
||||||
public Cart getCart(@Name("cartId") UUID cartId) throws GraphQLException {
|
public Cart getCart(@Name("cartId") UUID cartId) throws GraphQLException {
|
||||||
String key = "cart:" + cartId;
|
String key = "cart:" + cartId;
|
||||||
|
String priceKey = "cart_prices:" + cartId;
|
||||||
|
|
||||||
Map<String, String> data = hashCommands.hgetall(key);
|
Map<String, String> data = hashCommands.hgetall(key);
|
||||||
|
Map<String, String> itemPrices = hashCommands.hgetall(priceKey);
|
||||||
|
String managerId = hashCommands.hget(key, "_metadata_eateryManagerId");
|
||||||
|
|
||||||
if (data.isEmpty()) {
|
if (data.isEmpty()) {
|
||||||
throw new GraphQLException("NotFoundCart");
|
throw new GraphQLException("NotFoundCart");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CartItem> items = new ArrayList<>();
|
Cart cart = new Cart();
|
||||||
|
cart.Id = cartId;
|
||||||
|
cart.eateryId = UUID.fromString(data.get("_metadata_eatery"));
|
||||||
|
cart.userId = UUID.fromString(data.get("_metadata_owner"));
|
||||||
|
cart.items = new ArrayList<>();
|
||||||
|
|
||||||
data.forEach((k, v) -> {
|
long total = 0;
|
||||||
if (!k.startsWith("_")) {
|
|
||||||
items.add(new CartItem(k, Integer.parseInt(v)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return new Cart(
|
for (Map.Entry<String, String> entry : data.entrySet()) {
|
||||||
cartId,
|
String field = entry.getKey();
|
||||||
UUID.fromString(data.get("_metadata_owner")),
|
if (field.startsWith("_metadata_")) continue;
|
||||||
UUID.fromString(data.get("_metadata_eatery")),
|
|
||||||
items
|
Integer qty = Integer.parseInt(entry.getValue());
|
||||||
);
|
Double price = Double.parseDouble(itemPrices.getOrDefault(field, "0"));
|
||||||
|
Double subTotal = qty * price;
|
||||||
|
|
||||||
|
CartItem item = new CartItem();
|
||||||
|
item.productId = field;
|
||||||
|
item.quantity = qty;
|
||||||
|
item.priceAtTimeOfAdding = price;
|
||||||
|
item.subTotal = subTotal;
|
||||||
|
|
||||||
|
cart.items.add(item);
|
||||||
|
total += subTotal;
|
||||||
|
}
|
||||||
|
cart.totalAmount = total;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Response response = managerController.getManagerPaymentQr(
|
||||||
|
UUID.fromString(managerId),
|
||||||
|
total,
|
||||||
|
cartId.toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
cart.paymentQrUrl = response.readEntity(String.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
cart.paymentQrUrl = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation("addItem")
|
@Mutation("addItem")
|
||||||
|
|||||||
Reference in New Issue
Block a user