File

src/app/_services/service/service.service.ts

Index

Properties
Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

createService
createService(service: IService)
Parameters :
Name Type Optional
service IService No
deleteService
deleteService(id: number)
Parameters :
Name Type Optional
id number No
Returns : Observable<void>
getServiceById
getServiceById(id: number)
Parameters :
Name Type Optional
id number No
getServices
getServices()
updateService
updateService(service: IService)
Parameters :
Name Type Optional
service IService No

Properties

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

results matching ""

    No results matching ""