feat(hotel-details): add delete button and functionality

This commit is contained in:
Jan Gleytenhoover 2024-11-26 09:00:26 +01:00
parent a069e2f630
commit ee7a4c995f
Signed by: jank
GPG Key ID: B267751B8AE29EFE
2 changed files with 8 additions and 0 deletions

@ -1,4 +1,5 @@
@if (hotel != null) { @if (hotel != null) {
<app-hotel-item [hotel]="hotel" [isDetail]="true"></app-hotel-item> <app-hotel-item [hotel]="hotel" [isDetail]="true"></app-hotel-item>
<app-hotel-form [hotel]="hotel"></app-hotel-form> <app-hotel-form [hotel]="hotel"></app-hotel-form>
<button (click)="delete()">DELETE</button>
} }

@ -20,6 +20,13 @@ export class HotelDetailsComponent implements OnInit {
constructor(private route: ActivatedRoute, private http: HttpClient, private router: Router) { } constructor(private route: ActivatedRoute, private http: HttpClient, private router: Router) { }
delete(): void {
if (confirm("Are u sure u want to delete this hotel")) {
this.http.delete<Hotel>("/api/hotels/" + this.route.snapshot.paramMap.get("id")).subscribe();
this.router.navigate(["/"]);
}
}
ngOnInit(): void { ngOnInit(): void {
const routeParams = this.route.snapshot.paramMap; const routeParams = this.route.snapshot.paramMap;
const hotelId = routeParams.get("id"); const hotelId = routeParams.get("id");