0% found this document useful (0 votes)
6 views1 page

Bookingservice

The document defines a BookingService class in Angular that provides methods for managing bookings through HTTP requests. It includes functionalities to create, retrieve, update, delete, and list bookings, as well as to get bookings specific to a user. The service uses the HttpClient module to interact with a RESTful API at the specified endpoint 'api/bookings'.

Uploaded by

cadidou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Bookingservice

The document defines a BookingService class in Angular that provides methods for managing bookings through HTTP requests. It includes functionalities to create, retrieve, update, delete, and list bookings, as well as to get bookings specific to a user. The service uses the HttpClient module to interact with a RESTful API at the specified endpoint 'api/bookings'.

Uploaded by

cadidou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// 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}`);
}
}

You might also like