@@ -269,7 +269,7 @@
default
- | Shipping Address |
+ {{userShipping.userShippingStreet1}}, {{userShipping.userShippingCity}}, {{userShipping.userShippingState}} |
@@ -283,7 +283,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
|