From c6504d3616fe7084af9eca3b14c1f2a656d2a4af Mon Sep 17 00:00:00 2001 From: Le Deng Date: Wed, 8 Mar 2017 15:30:53 -0500 Subject: [PATCH] latest --- bookstore-api/.idea/workspace.xml | 96 ++++++++++--------- .../bookstore/resource/PaymentResource.java | 32 +++++++ .../my-profile/my-profile.component.html | 22 ++--- .../my-profile/my-profile.component.ts | 10 ++ 4 files changed, 106 insertions(+), 54 deletions(-) diff --git a/bookstore-api/.idea/workspace.xml b/bookstore-api/.idea/workspace.xml index 56601aa..cc144e0 100644 --- a/bookstore-api/.idea/workspace.xml +++ b/bookstore-api/.idea/workspace.xml @@ -16,11 +16,11 @@ - + - - + + @@ -28,16 +28,36 @@ - + - + + + + + + + + + + + + + + + + + + + + + @@ -894,12 +914,12 @@ - + - @@ -1168,24 +1188,6 @@ - - - - - - - - - - - - - - - - - - @@ -1254,14 +1256,6 @@ - - - - - - - - @@ -1294,23 +1288,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - \ No newline at end of file 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 d9fbab4..281dbdc 100644 --- a/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java +++ b/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java @@ -43,8 +43,40 @@ public class PaymentResource { userService.updateUserBilling(userBilling, userPayment, user); 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) 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 832d38a..2ec0c1a 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 @@ -73,7 +73,7 @@

- +
@@ -92,7 +92,7 @@
{{userPayment.cardName}} - @@ -196,15 +196,15 @@ - - - - - - - - - + + + + + + + + + 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 a532ae0..a2a100c 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 @@ -44,6 +44,10 @@ export class MyProfileComponent implements OnInit { constructor (private paymentService:PaymentService, private loginService: LoginService, private userService: UserService, private router: Router){ } + selectedIndexChange(val :number ){ + this.selectedBillingTab=val; + } + onLogin() { this.loginService.sendCredential(this.credential.username, this.credential.password).subscribe( res=>{ @@ -107,6 +111,12 @@ export class MyProfileComponent implements OnInit { ); } + onUpdatePayment(payment:UserPayment) { + this.userPayment = payment; + this.userBilling = payment.userBilling; + this.selectedBillingTab=1; + } + onRemovePayment(id:number) { this.paymentService.removePayment(id).subscribe( res => {