2024-11-12 09:18:15 +01:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
2024-11-12 09:37:50 +01:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2024-11-12 09:18:15 +01:00
|
|
|
import { Hotel } from '../HotelItem/hotel';
|
2024-11-19 11:32:02 +01:00
|
|
|
import { CurrencyPipe, NgFor, NgForOf, NgIf } from '@angular/common';
|
2024-11-12 09:18:15 +01:00
|
|
|
import { StarRatingComponent } from '../star-rating/star-rating.component';
|
|
|
|
import { HotelItem } from '../HotelItem/HotelItem.component';
|
2024-11-12 09:37:50 +01:00
|
|
|
import { catchError, EMPTY } from 'rxjs';
|
2024-11-19 11:32:02 +01:00
|
|
|
import { HotelFormComponent } from '../hotel-form/hotel-form.component';
|
2024-11-12 09:18:15 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-hotel-details',
|
|
|
|
standalone: true,
|
2024-11-19 11:32:02 +01:00
|
|
|
imports: [CurrencyPipe, StarRatingComponent, HotelItem, HotelFormComponent, NgIf, NgForOf],
|
2024-11-12 09:18:15 +01:00
|
|
|
templateUrl: './hotel-details.component.html',
|
|
|
|
styleUrl: './hotel-details.component.css'
|
|
|
|
})
|
|
|
|
export class HotelDetailsComponent implements OnInit {
|
|
|
|
public hotel: any;
|
|
|
|
|
2024-11-12 09:37:50 +01:00
|
|
|
constructor(private route: ActivatedRoute, private http: HttpClient, private router: Router) { }
|
2024-11-12 09:18:15 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
const routeParams = this.route.snapshot.paramMap;
|
|
|
|
const hotelId = routeParams.get("id");
|
|
|
|
|
2024-11-12 09:37:50 +01:00
|
|
|
this.http.get<Hotel>("api/hotels/" + hotelId).pipe(
|
|
|
|
catchError(() => {
|
|
|
|
alert("Not Found");
|
|
|
|
this.router.navigate(["/"]);
|
|
|
|
|
|
|
|
return EMPTY;
|
|
|
|
})
|
|
|
|
).subscribe(res => {
|
2024-11-12 09:18:15 +01:00
|
|
|
this.hotel = res;
|
2024-11-12 09:37:50 +01:00
|
|
|
})
|
2024-11-12 09:18:15 +01:00
|
|
|
}
|
|
|
|
}
|