diff --git a/bookstore-api/.idea/uiDesigner.xml b/bookstore-api/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/bookstore-api/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/bookstore-api/.idea/workspace.xml b/bookstore-api/.idea/workspace.xml
index 1a06443..dd3f990 100644
--- a/bookstore-api/.idea/workspace.xml
+++ b/bookstore-api/.idea/workspace.xml
@@ -19,8 +19,8 @@
-
-
+
+
@@ -30,8 +30,94 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -39,11 +125,9 @@
-
+
-
-
-
+
@@ -51,11 +135,9 @@
-
+
-
-
-
+
@@ -64,8 +146,50 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -75,7 +199,9 @@
-
+
+
+
@@ -85,41 +211,39 @@
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -133,6 +257,8 @@
password
+ bookResource
+ bookDetail
@@ -184,6 +310,8 @@
+
+
@@ -202,7 +330,7 @@
-
+
@@ -222,6 +350,7 @@
+
@@ -539,7 +668,6 @@
-
@@ -553,6 +681,7 @@
+
@@ -982,15 +1111,16 @@
-
+
+
-
+
-
+
@@ -1010,13 +1140,12 @@
-
-
+
+
-
+
-
@@ -1024,6 +1153,7 @@
+
@@ -1034,7 +1164,7 @@
-
+
@@ -1043,24 +1173,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1220,14 +1332,6 @@
-
-
-
-
-
-
-
-
@@ -1236,11 +1340,7 @@
-
-
-
-
-
+
@@ -1328,11 +1428,171 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
@@ -1340,61 +1600,41 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java b/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java
index 9f64443..37fe20d 100644
--- a/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java
+++ b/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java
@@ -123,18 +123,6 @@ public class BookResource {
return book;
}
- @RequestMapping("/{id}")
- public ResponseEntity bookDetail(@PathVariable("id") Long id, Principal principal) {
- if (principal != null) {
- String username = principal.getName();
- User user = userService.findByUsername(username);
- }
-
- Book book = bookService.findOne(id);
-
- return new ResponseEntity("Book Found!", HttpStatus.OK);
- }
-
@RequestMapping(value = "/remove", method = RequestMethod.POST)
public ResponseEntity remove(
@RequestBody String id, Model model
diff --git a/bookstore-api/src/main/java/com/bookstore/resource/ShoppingCartResource.java b/bookstore-api/src/main/java/com/bookstore/resource/ShoppingCartResource.java
new file mode 100644
index 0000000..f75d050
--- /dev/null
+++ b/bookstore-api/src/main/java/com/bookstore/resource/ShoppingCartResource.java
@@ -0,0 +1,58 @@
+package com.bookstore.resource;
+
+import com.bookstore.domain.Book;
+import com.bookstore.domain.CartItem;
+import com.bookstore.domain.User;
+import com.bookstore.service.BookService;
+import com.bookstore.service.CartItemService;
+import com.bookstore.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.security.Principal;
+import java.util.HashMap;
+
+/**
+ * Created by z00382545 on 3/10/17.
+ */
+
+@RestController
+@RequestMapping("/cart")
+public class ShoppingCartResource {
+
+ @Autowired
+ private UserService userService;
+
+ @Autowired
+ private BookService bookService;
+
+ @Autowired
+ private CartItemService cartItemService;
+
+ @RequestMapping("/add")
+ public ResponseEntity addItem(
+ @RequestBody HashMap mapper,
+ Principal principal) {
+ String bookId = (String) mapper.get("bookId");
+ String qty = (String) mapper.get("qty");
+
+ User user = userService.findByUsername(principal.getName());
+ Book book = bookService.findOne(Long.parseLong(bookId));
+
+ if(Integer.parseInt(qty)>book.getInStockNumber()) {
+ return new ResponseEntity("Not Enough Stock!", HttpStatus.BAD_REQUEST);
+
+ }
+
+ CartItem cartItem = cartItemService.addBookToCartItem(book, user, Integer.parseInt(qty));
+
+ return new ResponseEntity("Book Added Successfully!", HttpStatus.OK);
+
+ }
+}
diff --git a/bookstore-api/target/classes/com/bookstore/resource/BookResource.class b/bookstore-api/target/classes/com/bookstore/resource/BookResource.class
index 6fc5b2f..f3efe6b 100644
Binary files a/bookstore-api/target/classes/com/bookstore/resource/BookResource.class and b/bookstore-api/target/classes/com/bookstore/resource/BookResource.class differ
diff --git a/bookstore-api/target/classes/com/bookstore/resource/ShoppingCartResource.class b/bookstore-api/target/classes/com/bookstore/resource/ShoppingCartResource.class
new file mode 100644
index 0000000..a9789b9
Binary files /dev/null and b/bookstore-api/target/classes/com/bookstore/resource/ShoppingCartResource.class differ
diff --git a/store-front/src/app/app.module.ts b/store-front/src/app/app.module.ts
index 19b836a..9a6cc94 100644
--- a/store-front/src/app/app.module.ts
+++ b/store-front/src/app/app.module.ts
@@ -19,6 +19,8 @@ import { UserService } from './services/user.service';
import { PaymentService } from './services/payment.service';
import { ShippingService } from './services/shipping.service';
import { BookService } from './services/book.service';
+import { CartService } from './services/cart.service';
+
import { MyAccountComponent } from './components/my-account/my-account.component';
import { MyProfileComponent } from './components/my-profile/my-profile.component';
import { BookListComponent } from './components/book-list/book-list.component';
@@ -50,7 +52,8 @@ import { ShoppingCartComponent } from './components/shopping-cart/shopping-cart.
UserService,
PaymentService,
ShippingService,
- BookService
+ BookService,
+ CartService
],
bootstrap: [AppComponent]
})
diff --git a/store-front/src/app/components/book-detail/book-detail.component.html b/store-front/src/app/components/book-detail/book-detail.component.html
index 43e33df..f3646a0 100644
--- a/store-front/src/app/components/book-detail/book-detail.component.html
+++ b/store-front/src/app/components/book-detail/book-detail.component.html
@@ -56,7 +56,7 @@
style="color: green;"> Only {{book.inStockNumber}} In
Stock
Unavailable
-
diff --git a/store-front/src/app/components/book-detail/book-detail.component.ts b/store-front/src/app/components/book-detail/book-detail.component.ts
index ee8d87f..d0d1c62 100644
--- a/store-front/src/app/components/book-detail/book-detail.component.ts
+++ b/store-front/src/app/components/book-detail/book-detail.component.ts
@@ -1,6 +1,7 @@
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import {Book} from "../../models/book";
import {BookService} from "../../services/book.service";
+import {CartService} from '../../services/cart.service';
import {Params, ActivatedRoute,Router} from "@angular/router";
import {Http} from "@angular/http";
import {AppConst} from '../../constants/app-const';
@@ -21,7 +22,12 @@ export class BookDetailComponent implements OnInit {
private addBookSuccess:boolean = false;
private notEnoughStock:boolean = false;
- constructor(private bookService: BookService, private route: ActivatedRoute, private router:Router) {
+ constructor(
+ private bookService: BookService,
+ private cartService: CartService,
+ private route: ActivatedRoute,
+ private router:Router
+ ) {
this.route.params.forEach((params: Params) => {
this.bookId = Number.parseInt(params['id']);
});
@@ -34,6 +40,19 @@ export class BookDetailComponent implements OnInit {
);
}
+ onAddToCart() {
+ this.cartService.addItem(this.bookId, this.qty).subscribe(
+ res => {
+ console.log(res.text());
+ this.addBookSuccess=true;
+ },
+ err => {
+ console.log(err.text());
+ this.notEnoughStock=true;
+ }
+ );
+ }
+
ngOnInit() {
}
diff --git a/store-front/src/app/models/cart-item.ts b/store-front/src/app/models/cart-item.ts
new file mode 100644
index 0000000..85d6c4f
--- /dev/null
+++ b/store-front/src/app/models/cart-item.ts
@@ -0,0 +1,14 @@
+import { Book } from './book';
+import { ShoppingCart } from './shopping-cart';
+import { Order } from './order';
+
+export class CartItem {
+
+ public id: number;
+ public qty: number;
+ public subtotal: number;
+ public book: Book;
+ public shoppingCart: ShoppingCart;
+ public order: Order;
+
+}
diff --git a/store-front/src/app/models/order.ts b/store-front/src/app/models/order.ts
new file mode 100644
index 0000000..23d2748
--- /dev/null
+++ b/store-front/src/app/models/order.ts
@@ -0,0 +1,2 @@
+export class Order {
+}
diff --git a/store-front/src/app/models/shopping-cart.ts b/store-front/src/app/models/shopping-cart.ts
new file mode 100644
index 0000000..ec790c7
--- /dev/null
+++ b/store-front/src/app/models/shopping-cart.ts
@@ -0,0 +1,9 @@
+import { User } from './user';
+
+export class ShoppingCart {
+
+ public id: number;
+ public grandTotal: number;
+ public user: User;
+
+}
diff --git a/store-front/src/app/services/cart.service.spec.ts b/store-front/src/app/services/cart.service.spec.ts
new file mode 100644
index 0000000..762adf4
--- /dev/null
+++ b/store-front/src/app/services/cart.service.spec.ts
@@ -0,0 +1,16 @@
+/* tslint:disable:no-unused-variable */
+
+import { TestBed, async, inject } from '@angular/core/testing';
+import { CartService } from './cart.service';
+
+describe('CartService', () => {
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ providers: [CartService]
+ });
+ });
+
+ it('should ...', inject([CartService], (service: CartService) => {
+ expect(service).toBeTruthy();
+ }));
+});
diff --git a/store-front/src/app/services/cart.service.ts b/store-front/src/app/services/cart.service.ts
new file mode 100644
index 0000000..3a12a2b
--- /dev/null
+++ b/store-front/src/app/services/cart.service.ts
@@ -0,0 +1,22 @@
+import { Injectable } from '@angular/core';
+import {Headers, Http} from "@angular/http";
+import {AppConst} from '../constants/app-const';
+
+@Injectable()
+export class CartService {
+
+ constructor(private http: Http) { }
+
+ addItem(id:number, qty:number) {
+ let url = AppConst.serverPath+"/cart/add";
+ let cartItemInfo = {
+ "bookId" : id,
+ "qty" : qty
+ }
+ let tokenHeader = new Headers ({
+ 'x-auth-token' : localStorage.getItem("xAuthToken")
+ });
+ return this.http.post(url, cartItemInfo, {headers : tokenHeader});
+ }
+
+}