src/app/_services/service/service.service.ts
Properties |
|
Methods |
constructor(http: HttpClient)
|
||||||
Parameters :
|
createService | ||||||
createService(service: IService)
|
||||||
Parameters :
Returns :
Observable<IService>
|
deleteService | ||||||
deleteService(id: number)
|
||||||
Parameters :
Returns :
Observable<void>
|
getServiceById | ||||||
getServiceById(id: number)
|
||||||
Parameters :
Returns :
Observable<IService>
|
getServices |
getServices()
|
Returns :
Observable<IService[]>
|
updateService | ||||||
updateService(service: IService)
|
||||||
Parameters :
Returns :
Observable<IService>
|
Private SUrl |
Default value : `${environment.apiBaseUrl}/services/`
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { IService } from 'src/app/_interfaces/servives/service';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root',
})
export class ServiceService {
//private SUrl = 'http://192.168.1.223:8001/services/'; // Remplacez par l'URL de votre API
private SUrl = `${environment.apiBaseUrl}/services/`;
constructor(private http: HttpClient) {}
// Get all services
getServices(): Observable<IService[]> {
return this.http.get<IService[]>(this.SUrl);
}
// Get a single service by id
getServiceById(id: number): Observable<IService> {
const url = `${this.SUrl}/${id}`;
return this.http.get<IService>(url);
}
// Create a new service
createService(service: IService): Observable<IService> {
return this.http.post<IService>(this.SUrl, service, {
headers: new HttpHeaders({
'Content-Type': 'application/json',
}),
});
}
// Update an existing service
updateService(service: IService): Observable<IService> {
const url = `${this.SUrl}/${service.service_id}`;
return this.http.put<IService>(url, service, {
headers: new HttpHeaders({
'Content-Type': 'application/json',
}),
});
}
// Delete a service
deleteService(id: number): Observable<void> {
const url = `${this.SUrl}/${id}`;
return this.http.delete<void>(url);
}
}