From 6c4fa0df90707290f56bd1b5307216a4a6f45838 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Wed, 25 Mar 2020 13:55:17 +0100 Subject: [PATCH] US08: Allow the user to delete an owner using the UI --- .../list-owners/list-owners.component.html | 2 +- .../component/list-owners/list-owners.component.ts | 13 +++++++++++++ .../wendys-friends/src/app/service/owner.service.ts | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html b/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html index a210f6f..8322421 100644 --- a/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html +++ b/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html @@ -30,7 +30,7 @@ {{ owner.name }} - + diff --git a/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.ts b/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.ts index 2cc2926..7a7f8bf 100644 --- a/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.ts +++ b/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.ts @@ -71,6 +71,19 @@ export class ListOwnersComponent implements OnInit { ); } + public deleteOwner(id: number, name: string) { + if(confirm("Are you sure you want to delete " + name + ". This action is irreversible.")) { + this.ownerService.deleteOwner(id).subscribe( + (res) => { + console.log('Successfully deleted owner'); + this.loadAllOwners(); + }, (error) => { + this.defaultServiceErrorHandling(error); + } + ); + } + } + private defaultServiceErrorHandling(error: any) { console.log(error); this.error = true; diff --git a/frontend/wendys-friends/src/app/service/owner.service.ts b/frontend/wendys-friends/src/app/service/owner.service.ts index 08091ec..67811db 100644 --- a/frontend/wendys-friends/src/app/service/owner.service.ts +++ b/frontend/wendys-friends/src/app/service/owner.service.ts @@ -57,4 +57,13 @@ export class OwnerService { console.log('Update owner with id ' + owner.id + ': '+ JSON.stringify(owner)); return this.httpClient.put(this.messageBaseUri + '/' + owner.id, owner); } + + /** + * Delete an owner from the backend + * @param id + */ + deleteOwner(id: number): Observable { + console.log('Delete owner with id ' + id); + return this.httpClient.delete(this.messageBaseUri + '/' + id); + } }