// booking.service.
ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Booking } from './booking.model';
@Injectable({
providedIn: 'root'
})
export class BookingService {
private apiUrl = 'api/bookings';
constructor(private http: HttpClient) {}
createBooking(booking: Booking): Observable<Booking> {
return this.http.post<Booking>(this.apiUrl, booking);
}
getBooking(id: string): Observable<Booking> {
return this.http.get<Booking>(`${this.apiUrl}/${id}`);
}
updateBooking(id: string, booking: Booking): Observable<Booking> {
return this.http.put<Booking>(`${this.apiUrl}/${id}`, booking);
}
deleteBooking(id: string): Observable<void> {
return this.http.delete<void>(`${this.apiUrl}/${id}`);
}
getAllBookings(): Observable<Booking[]> {
return this.http.get<Booking[]>(this.apiUrl);
}
getUserBookings(userId: string): Observable<Booking[]> {
return this.http.get<Booking[]>(`${this.apiUrl}/user/${userId}`);
}
}