Skip to content

Commit

Permalink
#5: Remove customer
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelRauber committed Feb 16, 2016
1 parent 6e9b2e7 commit a8cb186
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
@@ -1,3 +1,3 @@
<div id="list" class="pure-u-1">
<nfn-admin-customer-list-item template="ngFor #customer of customers" [customer]="customer"></nfn-admin-customer-list-item>
<nfn-admin-customer-list-item template="ngFor #customer of customers" [customer]="customer" (onDeleted)="refresh()"></nfn-admin-customer-list-item>
</div>
Expand Up @@ -16,6 +16,10 @@ export class AdminCustomerListComponent implements OnInit {
}

ngOnInit(): any {
this.refresh();
}

private refresh() {
this._customerApiService.list()
.subscribe(res => this.customers = res);
}
Expand Down
Expand Up @@ -7,4 +7,7 @@
<h5 class="email-name">{{ customer.firstName }} {{ customer.lastName }}</h5>
<h4 class="email-subject">Customer</h4>
</div>
<div class="pure-u-1-4">
<button class="pure-button pure-button-primary" (click)="removeCustomer()">Delete</button>
</div>
</div>
@@ -1,5 +1,6 @@
import {Component, Input} from 'angular2/core';
import {Component, Input, Output, EventEmitter} from 'angular2/core';
import {CustomerModel} from '../../model/customerModel';
import {CustomerApiService} from '../../services/customerApiService';

@Component({
selector: 'nfn-admin-customer-list-item',
Expand All @@ -9,4 +10,15 @@ import {CustomerModel} from '../../model/customerModel';
export class AdminCustomerListItemComponent {
@Input()
public customer: CustomerModel;

@Output()
public onDeleted: EventEmitter = new EventEmitter();

constructor(private _customerApiService: CustomerApiService) {
}

private removeCustomer() {
this._customerApiService.remove(this.customer.id)
.subscribe(() => this.onDeleted.emit(null));
}
}
9 changes: 9 additions & 0 deletions src/ng2client/app/services/customerApiService.ts
Expand Up @@ -36,6 +36,15 @@ export class CustomerApiService {
.toArray();*/
}

public remove(userId: number): Observable {
const headers = this.createHeaders();
const endpoint = `${this._urlService.apiUrl}customer/${userId}`;

return this._http.delete(endpoint, {
headers: headers
});
}

private createHeaders(): Headers {
const headers: Headers = new Headers();
headers.append('Content-Type', 'application/json');
Expand Down

0 comments on commit a8cb186

Please sign in to comment.