✨ Added POI service to manage points of interest, including methods to retrieve, add, update and delete POIs.
parent
55ba6b0f9f
commit
2f402710f0
@ -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<any>(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<any>(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<any>(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<any>(url, { headers });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue