From 361a09b0827e04067bfbbb473ef5127823784378 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Sun, 22 Mar 2020 15:44:21 +0100 Subject: [PATCH] US04: Make it possible to delete horses from the UI --- .../list-horses/list-horses.component.html | 2 +- .../list-horses/list-horses.component.ts | 11 +++++++++++ .../src/app/service/horse.service.ts | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.html b/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.html index 3be9fda..33f9aae 100644 --- a/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.html +++ b/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.html @@ -71,7 +71,7 @@ - + diff --git a/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.ts b/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.ts index 75ce81f..e6d2bc7 100644 --- a/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.ts +++ b/frontend/wendys-friends/src/app/component/list-horses/list-horses.component.ts @@ -91,6 +91,17 @@ export class ListHorsesComponent implements OnInit { ); } + public deleteHorse(id: number, name: string) { + if(confirm("Are you sure you want to delete " + name + ". This action is irreversible.")) { + this.horseService.deleteHorse(id).subscribe( + (res) => { + console.log('Successfully deleted horse'); + this.loadAllHorses(); + } + ); + } + } + private defaultServiceErrorHandling(error: any) { console.log(error); this.error = true; diff --git a/frontend/wendys-friends/src/app/service/horse.service.ts b/frontend/wendys-friends/src/app/service/horse.service.ts index 70b35a2..ba8d8df 100644 --- a/frontend/wendys-friends/src/app/service/horse.service.ts +++ b/frontend/wendys-friends/src/app/service/horse.service.ts @@ -48,13 +48,28 @@ export class HorseService { return this.httpClient.post(this.messageBaseUri, horse); } + /** + * Update a specific horse with the supplied values + * @param horse + */ updateHorse(horse: Horse): Observable { console.log('Update horse with id ' + horse.id + ': '+ JSON.stringify(horse)); return this.httpClient.put(this.messageBaseUri + '/' + horse.id, horse); } /** - * + * Delete a horse from the backend + * @param id + */ + deleteHorse(id: number): Observable { + console.log('Delete horse with id ' + id); + return this.httpClient.delete(this.messageBaseUri + '/' + id); + } + + /** + * Uploads a file to the remote server + * @param fileToUpload + * @param newFileName */ postFile(fileToUpload: File, newFileName: string): Observable { // Prepare the form