@@ -226,17 +226,15 @@ service / on new http:Listener(9098) {
226
226
units : 0
227
227
};
228
228
CartItemView [] cartItems = [];
229
- foreach stubs : CartItem item in cart .items {
230
- stubs : Product product = check getProduct (item .product_id );
231
-
229
+ foreach stubs : CartItem {product_id , quantity } in cart .items {
230
+ stubs : Product product = check getProduct (product_id );
232
231
stubs : Money convertedPrice = check convertCurrency (product .price_usd , currencyCookie .value );
233
-
234
- stubs : Money price = money : multiplySlow (convertedPrice , item .quantity );
232
+ stubs : Money price = money : multiplySlow (convertedPrice , quantity );
235
233
string renderedPrice = money : renderMoney (price );
236
234
cartItems .push ({
237
235
product ,
238
236
price : renderedPrice ,
239
- quantity : item . quantity
237
+ quantity : quantity
240
238
});
241
239
totalPrice = money : sum (totalPrice , price );
242
240
}
@@ -261,7 +259,7 @@ service / on new http:Listener(9098) {
261
259
262
260
# POST method to update the cart with a product.
263
261
#
264
- # + request - `AddToCartRequest` containing the product id of the product to add
262
+ # + request - `AddToCartRequest` containing the product id of the product to be added
265
263
# + cookieHeader - header containing the cookie
266
264
# + return - `http:Created` if successful or `http:Unauthorized` or `http:BadRequest` or `error` if an error occurs
267
265
resource function post cart(@http :Payload AddToCartRequest request ,
@@ -313,7 +311,7 @@ service / on new http:Listener(9098) {
313
311
314
312
# Post method to checkout the user's cart.
315
313
#
316
- # + request - `CheckoutRequest` containing user's details
314
+ # + request - `CheckoutRequest` containing user details
317
315
# + cookieHeader - header containing the cookie
318
316
# + return - `CheckoutResponse` if successful or an `http:Unauthorized` or `error` if an error occurs
319
317
resource function post cart/checkout(@http :Payload CheckoutRequest request ,
@@ -349,8 +347,8 @@ service / on new http:Listener(9098) {
349
347
350
348
stubs : Product [] recommendations = check getRecommendations (userId );
351
349
stubs : Money totalCost = orderResult .shipping_cost ;
352
- foreach stubs : OrderItem item in orderResult .items {
353
- stubs : Money multiplyRes = money : multiplySlow (item . cost , item . item .quantity );
350
+ foreach stubs : OrderItem { item , cost } in orderResult .items {
351
+ stubs : Money multiplyRes = money : multiplySlow (cost , item .quantity );
354
352
totalCost = money : sum (totalCost , multiplyRes );
355
353
}
356
354
@@ -369,7 +367,7 @@ service / on new http:Listener(9098) {
369
367
}
370
368
371
369
function getProductIdFromCart(stubs : Cart cart ) returns string [] {
372
- return from stubs : CartItem item in cart .items
373
- select item . product_id ;
370
+ return from stubs : CartItem { product_id } in cart .items
371
+ select product_id ;
374
372
}
375
373
}
0 commit comments