Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Reviewed-on: #61
This commit was merged in pull request #61.
This commit is contained in:
@@ -6,16 +6,15 @@ 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")
|
||||
@RegisterRestClient(configKey = "account")
|
||||
@Path(Role.Manager)
|
||||
public interface ManagerController {
|
||||
@GET
|
||||
@Path(Role.Manager + "/{id}/payment-qr")
|
||||
@Path("/{id}/payment-qr")
|
||||
public Response getManagerPaymentQr(
|
||||
@PathParam("id") UUID id,
|
||||
@PathParam("id") String id,
|
||||
@QueryParam("amount") Long amount,
|
||||
@QueryParam("cartId") String cartId
|
||||
);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class CartService {
|
||||
|
||||
@Inject
|
||||
public CartService(RedisDataSource ds) {
|
||||
this.hashCommands = ds.hash(String.class);
|
||||
this.hashCommands = ds.hash(String.class, String.class, String.class);
|
||||
this.valueCommands = ds.value(String.class);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class CartService {
|
||||
|
||||
String cartId = UUID.randomUUID().toString();
|
||||
String redisKey = "cart:" + cartId;
|
||||
String ownerId = response.getEntity().toString();
|
||||
String ownerId = response.readEntity(String.class);
|
||||
|
||||
hashCommands.hset(
|
||||
redisKey,
|
||||
@@ -100,7 +100,6 @@ public class CartService {
|
||||
|
||||
Map<String, String> data = hashCommands.hgetall(key);
|
||||
Map<String, String> itemPrices = hashCommands.hgetall(priceKey);
|
||||
String managerId = hashCommands.hget(key, "_metadata_eateryManagerId");
|
||||
|
||||
if (data.isEmpty()) {
|
||||
throw new GraphQLException("NotFoundCart");
|
||||
@@ -110,6 +109,7 @@ public class CartService {
|
||||
cart.Id = cartId;
|
||||
cart.eateryId = UUID.fromString(data.get("_metadata_eatery"));
|
||||
String ownerStr = data.get("_metadata_owner");
|
||||
String managerId = data.get("_metadata_eateryManagerId");
|
||||
cart.userId = "GUEST".equals(ownerStr) ? null : UUID.fromString(ownerStr);
|
||||
cart.items = new ArrayList<>();
|
||||
|
||||
@@ -136,7 +136,7 @@ public class CartService {
|
||||
|
||||
try {
|
||||
Response response = managerController.getManagerPaymentQr(
|
||||
UUID.fromString(managerId),
|
||||
managerId,
|
||||
total,
|
||||
cartId.toString()
|
||||
);
|
||||
@@ -144,6 +144,8 @@ public class CartService {
|
||||
cart.paymentQrUrl = response.readEntity(String.class);
|
||||
} catch (Exception e) {
|
||||
cart.paymentQrUrl = "";
|
||||
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
return cart;
|
||||
@@ -186,4 +188,21 @@ public class CartService {
|
||||
|
||||
return getCart(cartId);
|
||||
}
|
||||
|
||||
@Mutation("deleteCart")
|
||||
public Uni<Boolean> deleteCart(@Name("cartId") UUID cartId) {
|
||||
String key = "cart:" + cartId;
|
||||
String priceKey = "cart_prices:" + cartId;
|
||||
|
||||
return Uni.createFrom()
|
||||
.item(() -> {
|
||||
long deletedKeys = hashCommands
|
||||
.getDataSource()
|
||||
.key()
|
||||
.del(key, priceKey);
|
||||
|
||||
return deletedKeys > 0;
|
||||
})
|
||||
.runSubscriptionOn(Infrastructure.getDefaultWorkerPool());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -29,7 +28,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@QuarkusTest
|
||||
public class CartServiceTest {
|
||||
public class CartServiceTest_ {
|
||||
|
||||
@Inject
|
||||
CartService cartService;
|
||||
Reference in New Issue
Block a user