diff --git a/bookstore-api/.idea/workspace.xml b/bookstore-api/.idea/workspace.xml index 534a6f8..597616a 100644 --- a/bookstore-api/.idea/workspace.xml +++ b/bookstore-api/.idea/workspace.xml @@ -29,8 +29,8 @@ - - + + @@ -943,16 +943,16 @@ - + - - + @@ -965,7 +965,7 @@ - + @@ -1001,8 +1001,14 @@ 26 + + file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/PaymentResource.java + 56 + + - @@ -1359,8 +1365,8 @@ - - + + 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 fb02180..cf39483 100644 --- a/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java +++ b/bookstore-api/src/main/java/com/bookstore/resource/PaymentResource.java @@ -48,11 +48,11 @@ public class PaymentResource { @RequestMapping(value = "/add", method = RequestMethod.POST) public ResponseEntity addNewCreditCardPost( - @RequestBody HashMap mapper, + @RequestBody UserPayment userPayment, Principal principal, Model model) { User user = userService.findByUsername(principal.getName()); - UserPayment userPayment = (UserPayment) mapper.get("userPayment"); - UserBilling userBilling = (UserBilling) mapper.get("userBilling"); + + UserBilling userBilling = userPayment.getUserBilling(); userService.updateUserBilling(userBilling, userPayment, user); diff --git a/bookstore-api/target/classes/com/bookstore/resource/PaymentResource.class b/bookstore-api/target/classes/com/bookstore/resource/PaymentResource.class new file mode 100644 index 0000000..08fef87 Binary files /dev/null and b/bookstore-api/target/classes/com/bookstore/resource/PaymentResource.class differ diff --git a/store-front/src/app/app.module.ts b/store-front/src/app/app.module.ts index 1714959..c7f4ec2 100644 --- a/store-front/src/app/app.module.ts +++ b/store-front/src/app/app.module.ts @@ -13,6 +13,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 { MyAccountComponent } from './components/my-account/my-account.component'; import { MyProfileComponent } from './components/my-profile/my-profile.component'; @@ -33,7 +34,8 @@ import { MyProfileComponent } from './components/my-profile/my-profile.component ], providers: [ LoginService, - UserService + UserService, + PaymentService ], 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 12afe0e..91bf39f 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 @@ -104,7 +104,7 @@ -
+
User info updated.
@@ -240,7 +240,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 17e3d78..df6f16e 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 @@ -3,6 +3,7 @@ import {AppConst} from '../../constants/app-const'; import {Router} from "@angular/router"; import {LoginService} from "../../services/login.service"; import {UserService} from "../../services/user.service"; +import {PaymentService} from "../../services/payment.service"; import {User} from '../../models/user'; import {UserPayment} from '../../models/user-payment'; import {UserBilling} from '../../models/user-billing'; @@ -35,7 +36,7 @@ export class MyProfileComponent implements OnInit { private userPaymentList: UserPayment[] = []; private stateList: string[] = []; - constructor (private loginService: LoginService, private userService: UserService, private router: Router){ + constructor (private paymentService:PaymentService, private loginService: LoginService, private userService: UserService, private router: Router){ } onLogin() { @@ -90,6 +91,17 @@ export class MyProfileComponent implements OnInit { ); } + onNewPayment () { + this.paymentService.newPayment(this.userPayment).subscribe( + res => { + console.log(res); + }, + error => { + console.log(error.text()); + } + ); + } + ngOnInit() { this.loginService.checkSession().subscribe( res => { @@ -119,5 +131,6 @@ export class MyProfileComponent implements OnInit { this.userPayment.type=""; this.userPayment.expiryMonth=""; this.userPayment.expiryYear=""; + this.userPayment.userBilling = this.userBilling; } } diff --git a/store-front/src/app/services/payment.service.ts b/store-front/src/app/services/payment.service.ts index 3301e9e..d51f1f5 100644 --- a/store-front/src/app/services/payment.service.ts +++ b/store-front/src/app/services/payment.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import {AppConst} from '../constants/app-const'; import {Http, Headers} from '@angular/http'; +import {UserPayment} from '../models/user-payment'; @Injectable() export class PaymentService { @@ -8,7 +9,13 @@ export class PaymentService { constructor(private http:Http) { } - getUserPaymentlist() { - + newPayment(payment: UsePayment) { + let url = this.serverPath+"/payment/add"; + + let tokenHeader = new Headers ({ + 'Content-Type': 'application/json', + 'x-auth-token' : localStorage.getItem("xAuthToken") + }); + return this.http.post(url, JSON.stringify(payment), {headers : tokenHeader}); } } \ No newline at end of file