chore: update
This commit is contained in:
@@ -150,11 +150,11 @@ public class CartService {
|
||||
}
|
||||
|
||||
@Mutation("addItem")
|
||||
public Uni<Cart> addItem(
|
||||
public Cart addItem(
|
||||
@Name("cartId") UUID cartId,
|
||||
@Name("menuItemId") UUID menuItemId,
|
||||
@Name("quantity") long quantity
|
||||
) {
|
||||
) throws GraphQLException {
|
||||
String key = "cart:" + cartId;
|
||||
String priceKey = "cart_prices:" + cartId;
|
||||
|
||||
@@ -163,18 +163,18 @@ public class CartService {
|
||||
|
||||
UUID eateryId = UUID.fromString(eateryIdStr);
|
||||
|
||||
return eateryController
|
||||
Response response = eateryController
|
||||
.checkMenuItemExists(eateryId, menuItemId)
|
||||
.onItem()
|
||||
.transform(response -> {
|
||||
.await()
|
||||
.indefinitely();
|
||||
|
||||
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
|
||||
throw new RuntimeException("NotFoundMenuItemInEatery");
|
||||
throw new GraphQLException("NotFoundMenuItemInEatery");
|
||||
}
|
||||
|
||||
Double menuItemPrice = response.readEntity(Double.class);
|
||||
|
||||
hashCommands.hincrby(key, menuItemId.toString(), quantity);
|
||||
|
||||
hashCommands.hset(
|
||||
priceKey,
|
||||
menuItemId.toString(),
|
||||
@@ -182,16 +182,8 @@ public class CartService {
|
||||
);
|
||||
|
||||
hashCommands.getDataSource().key().expire(key, Duration.ofDays(30));
|
||||
hashCommands
|
||||
.getDataSource()
|
||||
.key()
|
||||
.expire(priceKey, Duration.ofDays(30));
|
||||
hashCommands.getDataSource().key().expire(priceKey, Duration.ofDays(30));
|
||||
|
||||
try {
|
||||
return getCart(cartId);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class CartServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddItem_Success() {
|
||||
void testAddItem_Success() throws GraphQLException {
|
||||
UUID cartId = UUID.randomUUID();
|
||||
UUID eateryId = UUID.randomUUID();
|
||||
UUID menuItemId = UUID.randomUUID();
|
||||
@@ -137,10 +137,7 @@ public class CartServiceTest {
|
||||
Uni.createFrom().item(Response.ok(17.0).build())
|
||||
);
|
||||
|
||||
Cart result = cartService
|
||||
.addItem(cartId, menuItemId, 2L)
|
||||
.await()
|
||||
.atMost(Duration.ofSeconds(5));
|
||||
Cart result = cartService.addItem(cartId, menuItemId, 2L);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(cartId, result.getId());
|
||||
|
||||
Reference in New Issue
Block a user