diff --git a/src/app/services/poi.service.ts b/src/app/services/poi.service.ts new file mode 100644 index 0000000..d083d79 --- /dev/null +++ b/src/app/services/poi.service.ts @@ -0,0 +1,51 @@ +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { environment } from '../../environment'; +import { POI } from '../model/POI'; +import { AuthService } from './auth.service'; + +@Injectable({ + providedIn: 'root', +}) +export class POIService { + allPOIs: POI[] = []; + filteredPOIs: POI[] = []; + + private apiURL = environment.apiURL; + + constructor(private http: HttpClient, private authService: AuthService) {} + + getPOIs(): any { + const url = `${this.apiURL}/pins?poi=true`; + const headers = this.authService.getAuthHeaders(); + headers.set('Content-Type', 'application/json'); + + return this.http.get(url, { headers }); + } + + addPOI(poi: POI) { + const url = `${this.apiURL}/pin/add`; + const headers = this.authService.getAuthHeaders(); + headers.set('Content-Type', 'application/json'); + + return this.http.post(url, poi, { headers }); + } + + updatePOI(id: string, poi: POI) { + const url = `${this.apiURL}/pin/${id}`; + const headers = this.authService.getAuthHeaders(); + headers.set('Content-Type', 'application/json'); + + // Obtenir les coordonnées GPS à partir de l'adresse + return this.http.patch(url, poi, { headers }); + } + + deletePOI(id: string) { + const url = `${this.apiURL}/pin/${id}`; + const headers = this.authService.getAuthHeaders(); + headers.set('Content-Type', 'application/json'); + + return this.http.delete(url, { headers }); + } + +}