getCartItemList(Principal principal) {
User user = userService.findByUsername(principal.getName());
ShoppingCart shoppingCart = user.getShoppingCart();
@@ -74,4 +74,14 @@ public class ShoppingCartResource {
return cartItemList;
}
+
+ @RequestMapping("/getShoppingCart")
+ public ShoppingCart getShoppingCart(Principal principal) {
+ User user = userService.findByUsername(principal.getName());
+ ShoppingCart shoppingCart = user.getShoppingCart();
+
+ shoppingCartService.updateShoppingCart(shoppingCart);
+
+ return shoppingCart;
+ }
}
diff --git a/bookstore-api/target/classes/com/bookstore/domain/CartItem.class b/bookstore-api/target/classes/com/bookstore/domain/CartItem.class
index 99b6e97..7b26ef7 100644
Binary files a/bookstore-api/target/classes/com/bookstore/domain/CartItem.class and b/bookstore-api/target/classes/com/bookstore/domain/CartItem.class differ
diff --git a/bookstore-api/target/classes/com/bookstore/resource/ShoppingCartResource.class b/bookstore-api/target/classes/com/bookstore/resource/ShoppingCartResource.class
index 447af1e..b24e8e5 100644
Binary files a/bookstore-api/target/classes/com/bookstore/resource/ShoppingCartResource.class and b/bookstore-api/target/classes/com/bookstore/resource/ShoppingCartResource.class differ
diff --git a/store-front/src/app/components/shopping-cart/shopping-cart.component.html b/store-front/src/app/components/shopping-cart/shopping-cart.component.html
index 2d86d80..1c892bb 100644
--- a/store-front/src/app/components/shopping-cart/shopping-cart.component.html
+++ b/store-front/src/app/components/shopping-cart/shopping-cart.component.html
@@ -66,9 +66,9 @@
Total Price ( items): {{cartItemNumber}} items): $
+ >{{shoppingCart.grandTotal}}
diff --git a/store-front/src/app/components/shopping-cart/shopping-cart.component.ts b/store-front/src/app/components/shopping-cart/shopping-cart.component.ts
index 409ccce..7ec1c44 100644
--- a/store-front/src/app/components/shopping-cart/shopping-cart.component.ts
+++ b/store-front/src/app/components/shopping-cart/shopping-cart.component.ts
@@ -4,7 +4,7 @@ import {Book} from '../../models/book';
import {Router} from "@angular/router";
import {CartService} from '../../services/cart.service';
import {CartItem} from '../../models/cart-item';
-
+import {ShoppingCart} from '../../models/shopping-cart';
@Component({
selector: 'app-shopping-cart',
@@ -15,6 +15,8 @@ export class ShoppingCartComponent implements OnInit {
private serverPath = AppConst.serverPath;
private selectedBook: Book;
private cartItemList: CartItem[] = [];
+ private cartItemNumber: number;
+ private shoppingCart: ShoppingCart = new ShoppingCart();
constructor(private router:Router, private cartService: CartService) { }
@@ -24,15 +26,25 @@ export class ShoppingCartComponent implements OnInit {
}
ngOnInit() {
- this.cartService.getCart().subscribe(
+ this.cartService.getCartItemList().subscribe(
res=>{
- console.log(res.json());
this.cartItemList = res.json();
+ this.cartItemNumber = this.cartItemList.length;
},
error=>{
console.log(error.text());
}
);
+
+ this.cartService.getShoppingCart().subscribe(
+ res=>{
+ console.log(res.json());
+ this.shoppingCart=res.json();
+ },
+ error=>{
+ console.log(error.text());
+ }
+ );
}
}
diff --git a/store-front/src/app/services/cart.service.ts b/store-front/src/app/services/cart.service.ts
index 97ef934..0aacfbc 100644
--- a/store-front/src/app/services/cart.service.ts
+++ b/store-front/src/app/services/cart.service.ts
@@ -19,8 +19,17 @@ export class CartService {
return this.http.post(url, cartItemInfo, {headers : tokenHeader});
}
- getCart() {
- let url = AppConst.serverPath+"/cart/getCart";
+ getCartItemList() {
+ let url = AppConst.serverPath+"/cart/getCartItemList";
+
+ let tokenHeader = new Headers ({
+ 'x-auth-token' : localStorage.getItem("xAuthToken")
+ });
+ return this.http.get(url, {headers : tokenHeader});
+ }
+
+ getShoppingCart() {
+ let url = AppConst.serverPath+"/cart/getShoppingCart";
let tokenHeader = new Headers ({
'x-auth-token' : localStorage.getItem("xAuthToken")