US04: Make it possible to delete horses from the UI

This commit is contained in:
Ivaylo Ivanov 2020-03-22 15:44:21 +01:00
parent a3f6276fc4
commit 361a09b082
3 changed files with 28 additions and 2 deletions

View File

@ -71,7 +71,7 @@
<a class="btn btn-success" href="horse/{{ horse.id }}/edit"><i class="fas fa-edit"></i></a>
</td>
<td>
<button class="btn btn-danger"><i class="fas fa-trash"></i></button>
<button class="btn btn-danger" (click)="deleteHorse(horse.id, horse.name)"><i class="fas fa-trash"></i></button>
</td>
</tr>
</tbody>

View File

@ -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;

View File

@ -48,13 +48,28 @@ export class HorseService {
return this.httpClient.post<Horse>(this.messageBaseUri, horse);
}
/**
* Update a specific horse with the supplied values
* @param horse
*/
updateHorse(horse: Horse): Observable<Horse> {
console.log('Update horse with id ' + horse.id + ': '+ JSON.stringify(horse));
return this.httpClient.put<Horse>(this.messageBaseUri + '/' + horse.id, horse);
}
/**
*
* Delete a horse from the backend
* @param id
*/
deleteHorse(id: number): Observable<Object> {
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<Object> {
// Prepare the form