From e50a47f180676ede4ca025452bd0a65b8aaee6cb Mon Sep 17 00:00:00 2001 From: Le Deng Date: Thu, 9 Mar 2017 09:21:18 -0500 Subject: [PATCH] latest --- bookstore-api/.idea/workspace.xml | 124 ++++++++++++------ .../com/bookstore/domain/UserShipping.java | 3 + .../bookstore/resource/PaymentResource.java | 66 +++++----- .../bookstore/resource/ShippingResource.java | 70 ++++++++++ .../com/bookstore/domain/UserShipping.class | Bin 3098 -> 3150 bytes .../bookstore/resource/PaymentResource.class | Bin 3299 -> 3299 bytes .../bookstore/resource/ShippingResource.class | Bin 0 -> 2968 bytes store-front/src/app/app.module.ts | 4 +- .../my-profile/my-profile.component.html | 10 +- .../my-profile/my-profile.component.ts | 79 ++++++++++- store-front/src/app/models/user.ts | 2 + .../src/app/services/shipping.service.spec.ts | 16 +++ .../src/app/services/shipping.service.ts | 41 ++++++ 13 files changed, 333 insertions(+), 82 deletions(-) create mode 100644 bookstore-api/src/main/java/com/bookstore/resource/ShippingResource.java create mode 100644 bookstore-api/target/classes/com/bookstore/resource/ShippingResource.class create mode 100644 store-front/src/app/services/shipping.service.spec.ts create mode 100644 store-front/src/app/services/shipping.service.ts diff --git a/bookstore-api/.idea/workspace.xml b/bookstore-api/.idea/workspace.xml index 1114214..ea61eed 100644 --- a/bookstore-api/.idea/workspace.xml +++ b/bookstore-api/.idea/workspace.xml @@ -16,11 +16,11 @@ - + - - + + @@ -28,6 +28,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -91,7 +133,6 @@ @@ -914,12 +957,12 @@ - + - @@ -942,7 +985,7 @@ - + @@ -975,28 +1018,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -1109,13 +1130,6 @@ - - - - - - - @@ -1312,15 +1326,49 @@ + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bookstore-api/src/main/java/com/bookstore/domain/UserShipping.java b/bookstore-api/src/main/java/com/bookstore/domain/UserShipping.java index 8daf062..26968f8 100644 --- a/bookstore-api/src/main/java/com/bookstore/domain/UserShipping.java +++ b/bookstore-api/src/main/java/com/bookstore/domain/UserShipping.java @@ -1,5 +1,7 @@ package com.bookstore.domain; +import com.fasterxml.jackson.annotation.JsonIgnore; + import javax.persistence.*; import java.io.Serializable; @@ -25,6 +27,7 @@ public class UserShipping implements Serializable { @ManyToOne @JoinColumn(name = "user_id") + @JsonIgnore private User user; public Long getId() { diff --git a/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java b/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java index 281dbdc..7e59f6b 100644 --- a/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java +++ b/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java @@ -45,39 +45,39 @@ public class PaymentResource { return new ResponseEntity("Payment Added(Updated) Successfully!", HttpStatus.OK); } - @RequestMapping("/update") - public ResponseEntity updateCreditCard( - @RequestBody String id, Principal principal, - Model model - ) { - - User user = userService.findByUsername(principal.getName()); - UserPayment userPayment = userPaymentService.findById(Long.parseLong(id)); - - if (user.getId()!=userPayment.getUser().getId()) { - return new ResponseEntity("Invalid Request", HttpStatus.BAD_REQUEST); - } else { - - model.addAttribute("user", user); - UserBilling userBilling = userPayment.getUserBilling(); - model.addAttribute("userPayment", userPayment); - model.addAttribute("userBilling", userBilling); - - List stateList = USConstants.listOfUSStatesCode; - Collections.sort(stateList); - model.addAttribute("stateList", stateList); - - model.addAttribute("addNewCreditCard", true); - model.addAttribute("classActiveBilling", true); - model.addAttribute("listOfShippingAddresses", true); - model.addAttribute("userPaymentList", user.getUserPaymentList()); - model.addAttribute("userShippingList", user.getUserShippingList()); - model.addAttribute("orderList", user.getOrderList()); - - - return new ResponseEntity("Payment Added(Updated) Successfully!", HttpStatus.OK); - } - } +// @RequestMapping("/update") +// public ResponseEntity updateCreditCard( +// @RequestBody String id, Principal principal, +// Model model +// ) { +// +// User user = userService.findByUsername(principal.getName()); +// UserPayment userPayment = userPaymentService.findById(Long.parseLong(id)); +// +// if (user.getId()!=userPayment.getUser().getId()) { +// return new ResponseEntity("Invalid Request", HttpStatus.BAD_REQUEST); +// } else { +// +// model.addAttribute("user", user); +// UserBilling userBilling = userPayment.getUserBilling(); +// model.addAttribute("userPayment", userPayment); +// model.addAttribute("userBilling", userBilling); +// +// List stateList = USConstants.listOfUSStatesCode; +// Collections.sort(stateList); +// model.addAttribute("stateList", stateList); +// +// model.addAttribute("addNewCreditCard", true); +// model.addAttribute("classActiveBilling", true); +// model.addAttribute("listOfShippingAddresses", true); +// model.addAttribute("userPaymentList", user.getUserPaymentList()); +// model.addAttribute("userShippingList", user.getUserShippingList()); +// model.addAttribute("orderList", user.getOrderList()); +// +// +// return new ResponseEntity("Payment Added(Updated) Successfully!", HttpStatus.OK); +// } +// } @RequestMapping(value = "/remove", method = RequestMethod.POST) public ResponseEntity removePaymentPost( diff --git a/bookstore-api/src/main/java/com/bookstore/resource/ShippingResource.java b/bookstore-api/src/main/java/com/bookstore/resource/ShippingResource.java new file mode 100644 index 0000000..86799b2 --- /dev/null +++ b/bookstore-api/src/main/java/com/bookstore/resource/ShippingResource.java @@ -0,0 +1,70 @@ +package com.bookstore.resource; + +import com.bookstore.domain.User; +import com.bookstore.domain.UserBilling; +import com.bookstore.domain.UserPayment; +import com.bookstore.domain.UserShipping; +import com.bookstore.service.ShippingAddressService; +import com.bookstore.service.UserPaymentService; +import com.bookstore.service.UserService; +import com.bookstore.service.UserShippingService; +import com.bookstore.utility.USConstants; +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.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.security.Principal; +import java.util.Collections; +import java.util.List; + +/** + * Created by z00382545 on 3/9/17. + */ + +@RestController +@RequestMapping("/shipping") +public class ShippingResource { + @Autowired + private UserService userService; + + @Autowired + private UserShippingService userShippingService; + + @RequestMapping(value = "/add", method = RequestMethod.POST) + public ResponseEntity AddNewUserShippingPost( + @RequestBody UserShipping userShipping, + Principal principal, Model model) { + User user = userService.findByUsername(principal.getName()); + + + userService.updateUserShipping(userShipping, user); + + return new ResponseEntity("Shipping Added(Updated) Successfully!", HttpStatus.OK); + } + + @RequestMapping(value = "/remove", method = RequestMethod.POST) + public ResponseEntity removeUserShippingPost( + @RequestBody String id, + Principal principal, Model model) { + User user = userService.findByUsername(principal.getName()); + + userShippingService.removeById(Long.parseLong(id)); + + return new ResponseEntity("Shipping Removed Successfully!", HttpStatus.OK); + } + + @RequestMapping(value = "/setDefault", method = RequestMethod.POST) + public ResponseEntity setDefaultUserShippingPost( + @RequestBody String id, + Principal principal, Model model) { + User user = userService.findByUsername(principal.getName()); + userService.setUserDefaultShipping(Long.parseLong(id), user); + + return new ResponseEntity("Set Default Shipping Successfully!", HttpStatus.OK); + } +} diff --git a/bookstore-api/target/classes/com/bookstore/domain/UserShipping.class b/bookstore-api/target/classes/com/bookstore/domain/UserShipping.class index d0aae99e063caba1499e801ba131d0b7f09113ec..06794c78c76502f178a0532df6b0b3e08b1d3c97 100644 GIT binary patch literal 3150 zcmaKu-&b2j5Xa|+gg^+kkPvN=YN^&hE!U#bS}K)>QWI06Y)<9BXCNVa=bif=o7MHG)u*4ic^V2 znMH-gGZx>n_>M)D#rG_JVDV#=o=52*N9ixDAKosP3SjIZ zvf>N7)3If9&uR;U=0~uLUKi_7PmJneRS55nc6D7jGh=%|nj1Fa{#vK^1ZE$p$Uv>rUIOInJ@`IbC5koVI04vy4s9FKIIP)RLzqryw~Q z*EIV%$CeqV)oV-6mh@8-WoHL`x3_(NhZgRsd(v*1M^^pVb);zxZ`90To^49d;DE^o zwzR!1gC^1|6`Ysx!@88WrP%AWYoc4SP!F7Zr;a+aP;HnG7Q@~P8wGMBIL5OZgr`VT zcv%q6r&mTUa!`K}x4)T4t9wk9f+=V0?6l!MC&$hj7DWoDY4sOIj~}Q9J3z_kPr^n* zLF$)NLUG(*O)9!YJT0U&sVEPY)nJDesIr`IDCZBWQ?(dwLYrr%jvpcV2y)V2oTWSX9q%j9I(>|pfiK&qkmJUGQ0O=lz$RjPtwjN|s1=$72lK>EYBn;a?@0K%`7L3XqtQ!2>5 z7UZ!WWJ(380OVN!2)79a*+tG?f4E0E8PRXJk)%H8W~Pj00?({{PRv< P`=Nj1e;T+0?-TtGWI02g literal 3098 zcmaKuZC6`G5Xa|+gg{88K!~!WCU75KR>sMq_@!^VZR+_J~wHIux)^uGgw% zF!pe=$_sgTDBaeM(-9U;4`5e=z517&$8JXZ*}?52^Y{QL0rO5+n9-2J@|e*AhuWNGTftL7N^_cVq}C7HuPB}6 zWI@}%Uv0Wae<2-tprVk$(<&|#7HvO?-3rhxV!q_lvWkoRV0sN|8>59Wwe%-he<)uYa#SfN=u>>ph6Z$Soj-1y3mf%oJ%Wo)g5;~)_3zWjeaQJ*^6@_QCFn1Q+p}Pi< z5gp`;5#)3F!UQs+gDeB&Y77Y94ySL$2$Ix6Y$M3386>HL+yuz27!WQG2KmwmlF~u$ z7(v#|ASoSW1t6<2AY7jea?c1ds)O7!g4{QQjOrjofNaEo@B?9xbt6bx2iY`&d}Rhn z>mZK+Qi=iL7s?<-BgmKzQZ|BYm_f#LkP1MmF(BL`7~}yxgdBeRuW4Kdd1?gNq^~3A zq31iUgFFMs^B9n@H(9hr+Xj%#Z(1MOGlD!q!oyRXfXuz2j1JNONHYe6nD;ckyV;#5{g|3>{Ra0mXD=zk1yFv0); diff --git a/bookstore-api/target/classes/com/bookstore/resource/PaymentResource.class b/bookstore-api/target/classes/com/bookstore/resource/PaymentResource.class index db7f53873d36258860eff74b893ab1582ba93205..c40da5053afcc7fa2997c81b64bb0fee806299ae 100644 GIT binary patch delta 39 tcmaDX`B-v83pZ~VgCIjVgA79?gAPOV60UPx&hLb3EKbw delta 39 tcmaDX`B-v83pcMBgCK)BgA9WugARlBUx&gwr2>Sp4 diff --git a/bookstore-api/target/classes/com/bookstore/resource/ShippingResource.class b/bookstore-api/target/classes/com/bookstore/resource/ShippingResource.class new file mode 100644 index 0000000000000000000000000000000000000000..5ef163df17cf424e61df4344202b274e8379a35a GIT binary patch literal 2968 zcmcguYg5}+5IxrzjBS-9CLtwh5(rIWo5XV4JSe1T4J1v7c@zU}n!aS~8boBtm9Aj? zy`Aaw*R+|=B(yXA0r^px?v;hGjm$J(3Nw1#dw2JoJ-aKve)HEq0B&J7g$zDT;tcMm z@fki(ql9^RSx8`U7!Q(oh%ZtY!XtU+aSBU#A}{4Mma#I7Re5%87+)r^o((HeZ;cAl$Mu34^H*J|XorD~ypTJnUwZ#Y~hx1&Ck9i!PK+Yr+9Nszh^ zlaHZ$hGmHR3^Ir%{q?o@0oX zx<*N>8BNWci%gimkOBjN3FyRN?GQ3XoiH^hRSfk?A&U=(K)*if*EtpvVO@HL()_y*4yu15`} zh=yUfc8GI=I-Bd+&8DsiuIDByUaiJmx9*u{Ychdv6?}*9W#AtaoX5Kf{HQ=fRY47U z0$f2I+teAMyLDe{z1xq19T-$)6)q-%tWJa$T@i^x_h{}rl^9O@W5q9?)#@&<(KtHa zXVQ?g+gz+rQ8S#)=AyKp?2a4pNnjYMQ-{vCWJOrMFEyfqd*^D$>>)KXo}cN?qGBlh zrzzSEu+y#l22AzU{t->g3Vpde8v3!-CnSDkBl~r7be6ErcCu@yIC^CFno2w)N9vSq zi)tj<)Et+$pU-uA4mv-#L@N0MZnaKd$?Q_6Owx=H<+^jwB~s8NmBWvGs@==;t;f{v zqn!bLXA7wLpbcSiTY{7bMue3SR+DjfhGoTFdAEMC`@^ z1{e+yk6|`07pBMK2N)c{-xzwDNxZ=DOC*1%(=o^hBjkfD3I0urqWY0;wY>$A=>gjQkRIe8!$0y9HNne8A^2uT#^SLJP=L?I+m2uWP(OXAMS zB<_YJehWwxqe#R85>ks(fflEuX_Sb@Jmq__gGMo=Q4DDmLmI`9#+AM_W=^6J!zZK& T6^t)phMwl=Jx|$c3wiHf5bq{f literal 0 HcmV?d00001 diff --git a/store-front/src/app/app.module.ts b/store-front/src/app/app.module.ts index c7f4ec2..7c9ad77 100644 --- a/store-front/src/app/app.module.ts +++ b/store-front/src/app/app.module.ts @@ -14,6 +14,7 @@ import { NavBarComponent } from './components/nav-bar/nav-bar.component'; import { LoginService } from './services/login.service'; import { UserService } from './services/user.service'; import { PaymentService } from './services/payment.service'; +import { ShippingService } from './services/shipping.service'; import { MyAccountComponent } from './components/my-account/my-account.component'; import { MyProfileComponent } from './components/my-profile/my-profile.component'; @@ -35,7 +36,8 @@ import { MyProfileComponent } from './components/my-profile/my-profile.component providers: [ LoginService, UserService, - PaymentService + PaymentService, + ShippingService ], bootstrap: [AppComponent] }) diff --git a/store-front/src/app/components/my-profile/my-profile.component.html b/store-front/src/app/components/my-profile/my-profile.component.html index 256a647..a270abc 100644 --- a/store-front/src/app/components/my-profile/my-profile.component.html +++ b/store-front/src/app/components/my-profile/my-profile.component.html @@ -74,7 +74,7 @@

Default payment set successfully!

- +
@@ -252,7 +252,7 @@

Default shipping address set successfully!

- +
@@ -269,7 +269,7 @@ default - +
Shipping Address{{userShipping.userShippingStreet1}}, {{userShipping.userShippingCity}}, {{userShipping.userShippingState}} @@ -283,7 +283,7 @@ -
+
@@ -325,7 +325,7 @@

- +
diff --git a/store-front/src/app/components/my-profile/my-profile.component.ts b/store-front/src/app/components/my-profile/my-profile.component.ts index 25b1e51..cc15112 100644 --- a/store-front/src/app/components/my-profile/my-profile.component.ts +++ b/store-front/src/app/components/my-profile/my-profile.component.ts @@ -4,6 +4,7 @@ import {Router} from "@angular/router"; import {LoginService} from "../../services/login.service"; import {UserService} from "../../services/user.service"; import {PaymentService} from "../../services/payment.service"; +import {ShippingService} from "../../services/shipping.service"; import {User} from '../../models/user'; import {UserPayment} from '../../models/user-payment'; import {UserBilling} from '../../models/user-billing'; @@ -35,19 +36,34 @@ export class MyProfileComponent implements OnInit { private userPayment: UserPayment = new UserPayment(); private userBilling: UserBilling = new UserBilling(); private userPaymentList: UserPayment[] = []; - private stateList: string[] = []; private userShipping: UserShipping = new UserShipping(); + private userShippingList: UserShipping[] = []; + private stateList: string[] = []; private selectedProfileTab:number = 0; private selectedBillingTab:number = 0; + private selectedShippingTab:number = 0; private defaultUserPaymentId:number; private defaultPaymentSet:boolean; - constructor (private paymentService:PaymentService, private loginService: LoginService, private userService: UserService, private router: Router){ + private defaultUserShippingId:number; + private defaultShippingSet: boolean; + + constructor ( + private paymentService:PaymentService, + private shippingService:ShippingService, + private loginService: LoginService, + private userService: UserService, + private router: Router + ){ } - selectedIndexChange(val :number ){ + selectedShippingChange(val :number ){ + this.selectedShippingTab=val; + } + + selectedBillingChange(val :number ){ this.selectedBillingTab=val; } @@ -118,7 +134,6 @@ export class MyProfileComponent implements OnInit { onUpdatePayment(payment:UserPayment) { this.userPayment = payment; this.userBilling = payment.userBilling; - this.selectedBillingTab=1; } onRemovePayment(id:number) { @@ -148,16 +163,68 @@ export class MyProfileComponent implements OnInit { ); } + onNewShipping () { + this.shippingService.newShipping(this.userShipping).subscribe( + res => { + this.getCurrentUser(); + this.selectedShippingTab = 0; + }, + error => { + console.log(error.text()); + } + ); + } + + onUpdateShipping(shipping:UserShipping) { + this.userShipping = shipping; + this.selectedShippingTab=1; + } + + onRemoveShipping(id:number) { + this.shippingService.removeShipping(id).subscribe( + res => { + this.getCurrentUser(); + + }, + error => { + console.log(error.text()); + } + ); + } + + setDefaultShipping() { + this.defaultShippingSet=false; + this.shippingService.setDefaultShipping(this.defaultUserShippingId).subscribe( + res => { + this.getCurrentUser(); + this.defaultShippingSet=true; + // this.selectedProfileTab = 2; + // this.selectedBillingTab = 0; + }, + error => { + console.log(error.text()); + } + ); + } + getCurrentUser() { this.userService.getCurrentUser().subscribe( res => { this.user=res.json(); this.userPaymentList = this.user.userPaymentList; + this.userShippingList = this.user.userShippingList; for (let index in this.userPaymentList) { if (this.userPaymentList[index].defaultPayment) { this.defaultUserPaymentId=this.userPaymentList[index].id; - return; + break; + } + } + + for (let i in this.userShippingList) { + if (this.userShippingList[i].userShippingDefault) { + this.defaultUserShippingId=this.userShippingList[i].id; + break; } } }, @@ -191,5 +258,7 @@ export class MyProfileComponent implements OnInit { this.defaultPaymentSet=false; this.userShipping.userShippingState=""; + this.defaultShippingSet=false; + } } diff --git a/store-front/src/app/models/user.ts b/store-front/src/app/models/user.ts index b21549d..1c8c41a 100644 --- a/store-front/src/app/models/user.ts +++ b/store-front/src/app/models/user.ts @@ -1,4 +1,5 @@ import {UserPayment} from './user-payment'; +import {UserShipping} from './user-shipping'; export class User { public id: number; @@ -10,4 +11,5 @@ export class User { public phone: string; public enabled: boolean; public userPaymentList: UserPayment[]; + public userShippingList: UserShipping[]; } diff --git a/store-front/src/app/services/shipping.service.spec.ts b/store-front/src/app/services/shipping.service.spec.ts new file mode 100644 index 0000000..d4d2fcd --- /dev/null +++ b/store-front/src/app/services/shipping.service.spec.ts @@ -0,0 +1,16 @@ +/* tslint:disable:no-unused-variable */ + +import { TestBed, async, inject } from '@angular/core/testing'; +import { ShippingService } from './shipping.service'; + +describe('ShippingService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ShippingService] + }); + }); + + it('should ...', inject([ShippingService], (service: ShippingService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/store-front/src/app/services/shipping.service.ts b/store-front/src/app/services/shipping.service.ts new file mode 100644 index 0000000..970b2ef --- /dev/null +++ b/store-front/src/app/services/shipping.service.ts @@ -0,0 +1,41 @@ +import { Injectable } from '@angular/core'; +import {AppConst} from '../constants/app-const'; +import {Http, Headers} from '@angular/http'; +import {UserShipping} from '../models/user-shipping'; + +@Injectable() +export class ShippingService { + private serverPath:string = AppConst.serverPath; + + constructor(private http:Http) { } + + newShipping(shipping: UserShipping) { + let url = this.serverPath+"/shipping/add"; + + let tokenHeader = new Headers ({ + 'Content-Type': 'application/json', + 'x-auth-token' : localStorage.getItem("xAuthToken") + }); + return this.http.post(url, JSON.stringify(shipping), {headers : tokenHeader}); + } + + removeShipping(id: number) { + let url = this.serverPath+"/shipping/remove"; + + let tokenHeader = new Headers ({ + 'Content-Type': 'application/json', + 'x-auth-token' : localStorage.getItem("xAuthToken") + }); + return this.http.post(url, id, {headers : tokenHeader}); + } + + setDefaultShipping(id: number) { + let url = this.serverPath+"/shipping/setDefault"; + + let tokenHeader = new Headers ({ + 'Content-Type': 'application/json', + 'x-auth-token' : localStorage.getItem("xAuthToken") + }); + return this.http.post(url, id, {headers : tokenHeader}); + } +} \ No newline at end of file