diff --git a/bookstore-api/.idea/workspace.xml b/bookstore-api/.idea/workspace.xml index 7edefab..a005c12 100644 --- a/bookstore-api/.idea/workspace.xml +++ b/bookstore-api/.idea/workspace.xml @@ -19,8 +19,8 @@ - - + + @@ -28,6 +28,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -122,12 +152,12 @@ @@ -954,12 +984,12 @@ - + - @@ -1015,13 +1045,6 @@ - - - - - - - @@ -1377,14 +1400,6 @@ - - - - - - - - @@ -1437,14 +1452,6 @@ - - - - - - - - @@ -1477,10 +1484,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/bookstore-api/src/main/java/com/bookstore/domain/CartItem.java b/bookstore-api/src/main/java/com/bookstore/domain/CartItem.java index b207f5d..f69f7e9 100644 --- a/bookstore-api/src/main/java/com/bookstore/domain/CartItem.java +++ b/bookstore-api/src/main/java/com/bookstore/domain/CartItem.java @@ -36,6 +36,7 @@ public class CartItem implements Serializable { @ManyToOne @JoinColumn(name = "order_id") + @JsonIgnore private Order order; public Long getId() { diff --git a/bookstore-api/src/main/java/com/bookstore/domain/Order.java b/bookstore-api/src/main/java/com/bookstore/domain/Order.java index a8ede11..43a4b98 100644 --- a/bookstore-api/src/main/java/com/bookstore/domain/Order.java +++ b/bookstore-api/src/main/java/com/bookstore/domain/Order.java @@ -31,12 +31,15 @@ public class Order implements Serializable { private List cartItemList; @OneToOne(cascade=CascadeType.ALL) + @JsonIgnore private ShippingAddress shippingAddress; @OneToOne(cascade=CascadeType.ALL) + @JsonIgnore private BillingAddress billingAddress; @OneToOne(cascade=CascadeType.ALL) + @JsonIgnore private Payment payment; @ManyToOne @@ -130,4 +133,21 @@ public class Order implements Serializable { public void setUser(User user) { this.user = user; } + + @Override + public String toString() { + return "Order{" + + "id=" + id + + ", orderDate=" + orderDate + + ", shippingDate=" + shippingDate + + ", shippingMethod='" + shippingMethod + '\'' + + ", orderStatus='" + orderStatus + '\'' + + ", orderTotal=" + orderTotal + + ", cartItemList=" + cartItemList + + ", shippingAddress=" + shippingAddress + + ", billingAddress=" + billingAddress + + ", payment=" + payment + + ", user=" + user + + '}'; + } } diff --git a/bookstore-api/src/main/java/com/bookstore/resource/CheckoutResource.java b/bookstore-api/src/main/java/com/bookstore/resource/CheckoutResource.java index 21e3569..e9efd74 100644 --- a/bookstore-api/src/main/java/com/bookstore/resource/CheckoutResource.java +++ b/bookstore-api/src/main/java/com/bookstore/resource/CheckoutResource.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*; import java.security.Principal; import java.time.LocalDate; import java.util.*; +import java.util.concurrent.TimeUnit; /** * Created by z00382545 on 3/10/17. @@ -24,6 +25,8 @@ import java.util.*; @RequestMapping("/checkout") public class CheckoutResource { + private Order order = new Order(); + @Autowired private JavaMailSender mailSender; @@ -43,7 +46,7 @@ public class CheckoutResource { private MailConstructor mailConstructor; @RequestMapping(value = "/checkout", method = RequestMethod.POST) - public ResponseEntity checkoutPost( + public Order checkoutPost( @RequestBody HashMap mapper, Principal principal ) { @@ -78,7 +81,11 @@ public class CheckoutResource { estimatedDeliveryDate = today.plusDays(3); } - return new ResponseEntity("Order Checkout Successful!", HttpStatus.OK); + this.order = order; + + return order; } + + } diff --git a/bookstore-api/target/classes/com/bookstore/domain/CartItem.class b/bookstore-api/target/classes/com/bookstore/domain/CartItem.class index 7b26ef7..448fde3 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/domain/Order.class b/bookstore-api/target/classes/com/bookstore/domain/Order.class index 56fafe3..f82667b 100644 Binary files a/bookstore-api/target/classes/com/bookstore/domain/Order.class and b/bookstore-api/target/classes/com/bookstore/domain/Order.class differ diff --git a/bookstore-api/target/classes/com/bookstore/resource/CheckoutResource.class b/bookstore-api/target/classes/com/bookstore/resource/CheckoutResource.class index 7423619..0d0b0ea 100644 Binary files a/bookstore-api/target/classes/com/bookstore/resource/CheckoutResource.class and b/bookstore-api/target/classes/com/bookstore/resource/CheckoutResource.class differ diff --git a/store-front/src/app/components/order-summary/order-summary.component.ts b/store-front/src/app/components/order-summary/order-summary.component.ts index e30a500..eb7fa4c 100644 --- a/store-front/src/app/components/order-summary/order-summary.component.ts +++ b/store-front/src/app/components/order-summary/order-summary.component.ts @@ -1,5 +1,9 @@ -import { Component, OnInit } from '@angular/core'; -import {AppConst} from '../../constants/app-const'; +import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'; +import {Params, ActivatedRoute,Router} from "@angular/router"; +import { AppConst } from '../../constants/app-const'; +import { CheckoutService } from '../../services/checkout.service'; +import { Order } from '../../models/order'; +import { CartItem } from '../../models/cart-item'; @Component({ @@ -9,10 +13,39 @@ import {AppConst} from '../../constants/app-const'; }) export class OrderSummaryComponent implements OnInit { private serverPath = AppConst.serverPath; + private order:Order = new Order(); + private estimatedDeliveryDate:string; + private cartItemList:CartItem[] = []; - constructor() { } + constructor( + private checkoutService:CheckoutService, + private route: ActivatedRoute, + private router:Router + ) { + this.route.queryParams.subscribe(params => { + + this.order = JSON.parse(params['order']); + + let deliveryDate = new Date(); + + if (this.order.shippingMethod=="groundShipping") { + deliveryDate.setDate(deliveryDate.getDate()+5); + } else { + deliveryDate.setDate(deliveryDate.getDate()+3); + } + + let days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; + + this.estimatedDeliveryDate = days[deliveryDate.getDay()]+', '+deliveryDate.getFullYear()+'/'+deliveryDate.getMonth()+'/'+deliveryDate.getDate(); + + this.cartItemList = this.order.cartItemList; + + }); + } + ngOnInit() { + } } diff --git a/store-front/src/app/components/order/order.component.ts b/store-front/src/app/components/order/order.component.ts index 0717bed..676d63d 100644 --- a/store-front/src/app/components/order/order.component.ts +++ b/store-front/src/app/components/order/order.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import {AppConst} from '../../constants/app-const'; import {Book} from '../../models/book'; -import {Router} from "@angular/router"; +import {Router, NavigationExtras} from "@angular/router"; import {CartService} from '../../services/cart.service'; import {ShippingService} from '../../services/shipping.service'; import {PaymentService} from '../../services/payment.service'; @@ -14,7 +14,7 @@ import {UserPayment} from '../../models/user-payment'; import {UserBilling} from '../../models/user-billing'; import {UserShipping} from '../../models/user-shipping'; import {Payment} from '../../models/payment'; - +import {Order} from '../../models/order'; @Component({ selector: 'app-order', @@ -41,6 +41,7 @@ export class OrderComponent implements OnInit { private emptyPaymentList: boolean = true; private stateList: string[] = []; private shippingMethod:string; + private order:Order = new Order(); constructor( private router:Router, @@ -69,13 +70,13 @@ export class OrderComponent implements OnInit { getCartItemList(){ this.cartService.getCartItemList().subscribe( - res=>{ - this.cartItemList = res.json(); - this.cartItemNumber = this.cartItemList.length; - }, - error=>{ - console.log(error.text()); - } + res=>{ + this.cartItemList = res.json(); + this.cartItemNumber = this.cartItemList.length; + }, + error=>{ + console.log(error.text()); + } ); } @@ -110,58 +111,65 @@ export class OrderComponent implements OnInit { console.log("same as shipping") if(checked) { - this.billingAddress.billingAddressName = this.shippingAddress.shippingAddressName; - this.billingAddress.billingAddressStreet1 = this.shippingAddress.shippingAddressStreet1; - this.billingAddress.billingAddressStreet2 = this.shippingAddress.shippingAddressStreet2; - this.billingAddress.billingAddressCity = this.shippingAddress.shippingAddressCity; - this.billingAddress.billingAddressState = this.shippingAddress.shippingAddressState; - this.billingAddress.billingAddressCountry = this.shippingAddress.shippingAddressCountry; - this.billingAddress.billingAddressZipcode = this.shippingAddress.shippingAddressZipcode; - } else { - this.billingAddress.billingAddressName = ""; - this.billingAddress.billingAddressStreet1 = ""; - this.billingAddress.billingAddressStreet2 = ""; - this.billingAddress.billingAddressCity = ""; - this.billingAddress.billingAddressState = ""; - this.billingAddress.billingAddressCountry = ""; - this.billingAddress.billingAddressZipcode = ""; - } + this.billingAddress.billingAddressName = this.shippingAddress.shippingAddressName; + this.billingAddress.billingAddressStreet1 = this.shippingAddress.shippingAddressStreet1; + this.billingAddress.billingAddressStreet2 = this.shippingAddress.shippingAddressStreet2; + this.billingAddress.billingAddressCity = this.shippingAddress.shippingAddressCity; + this.billingAddress.billingAddressState = this.shippingAddress.shippingAddressState; + this.billingAddress.billingAddressCountry = this.shippingAddress.shippingAddressCountry; + this.billingAddress.billingAddressZipcode = this.shippingAddress.shippingAddressZipcode; + } else { + this.billingAddress.billingAddressName = ""; + this.billingAddress.billingAddressStreet1 = ""; + this.billingAddress.billingAddressStreet2 = ""; + this.billingAddress.billingAddressCity = ""; + this.billingAddress.billingAddressState = ""; + this.billingAddress.billingAddressCountry = ""; + this.billingAddress.billingAddressZipcode = ""; + } } onSubmit(){ this.checkoutService.checkout( - this.shippingAddress, - this.billingAddress, - this.payment, - this.shippingMethod - ).subscribe( + this.shippingAddress, + this.billingAddress, + this.payment, + this.shippingMethod + ).subscribe( res=>{ - console.log(res.text()); - }, - error=>{ - console.log(error.text()); - } - ); + this.order=res.json(); + console.log(this.order); - this.router.navigate(['/orderSummary']); - } + let navigationExtras: NavigationExtras = { + queryParams: { + "order": JSON.stringify(this.order) + } + }; - ngOnInit() { - this.getCartItemList(); - + this.router.navigate(['/orderSummary'], navigationExtras); + }, + error=>{ + console.log(error.text()); + } + ); + } - this.cartService.getShoppingCart().subscribe( - res=>{ + ngOnInit() { + this.getCartItemList(); + + + this.cartService.getShoppingCart().subscribe( + res=>{ console.log(res.json()); this.shoppingCart=res.json(); }, error=>{ console.log(error.text()); } - ); + ); - this.shippingService.getUserShippingList().subscribe( - res=>{ + this.shippingService.getUserShippingList().subscribe( + res=>{ console.log(res.json()); this.userShippingList=res.json(); this.emptyShippingList = false; @@ -169,10 +177,10 @@ export class OrderComponent implements OnInit { error=>{ console.log(error.text()); } - ); + ); - this.paymentService.getUserPaymentList().subscribe( - res=>{ + this.paymentService.getUserPaymentList().subscribe( + res=>{ console.log(res.json()); this.userPaymentList=res.json(); this.emptyPaymentList = false; @@ -180,20 +188,20 @@ export class OrderComponent implements OnInit { error=>{ console.log(error.text()); } - ); + ); - for (let s in AppConst.usStates) { - this.stateList.push(s); + for (let s in AppConst.usStates) { + this.stateList.push(s); + } + + this.payment.type=""; + this.payment.expiryMonth=""; + this.payment.expiryYear=""; + this.billingAddress.billingAddressState=""; + this.shippingAddress.shippingAddressState=""; + this.shippingMethod="groundShipping"; } - this.payment.type=""; - this.payment.expiryMonth=""; - this.payment.expiryYear=""; - this.billingAddress.billingAddressState=""; - this.shippingAddress.shippingAddressState=""; - this.shippingMethod="groundShipping"; + + } - - - -} diff --git a/store-front/src/app/models/order.ts b/store-front/src/app/models/order.ts index b9eceee..8ac9f03 100644 --- a/store-front/src/app/models/order.ts +++ b/store-front/src/app/models/order.ts @@ -1,3 +1,5 @@ +import {CartItem} from "./cart-item"; + export class Order { public id:number; public orderDate: string; @@ -5,4 +7,5 @@ export class Order { public shippingMethod: string; public orderStatus: string; public orderTotal: number; + public cartItemList: CartItem[]; } diff --git a/store-front/src/app/services/checkout.service.ts b/store-front/src/app/services/checkout.service.ts index c5d241f..d3ae4b3 100644 --- a/store-front/src/app/services/checkout.service.ts +++ b/store-front/src/app/services/checkout.service.ts @@ -29,4 +29,13 @@ export class CheckoutService { return this.http.post(url, order, {headers : tokenHeader}); } + getUserOrder() { + let url = AppConst.serverPath+"/checkout/getUserOrder"; + + let tokenHeader = new Headers ({ + 'x-auth-token' : localStorage.getItem("xAuthToken") + }); + return this.http.get(url, {headers : tokenHeader}); + } + }