|
|
|
@ -17,76 +17,41 @@ export class PinService {
|
|
|
|
|
constructor(private http: HttpClient, private authService: AuthService) {}
|
|
|
|
|
|
|
|
|
|
getPinById(id: string) {
|
|
|
|
|
const url = `${this.apiURL}/pin/${id}`;
|
|
|
|
|
const headers = this.authService.getAuthHeaders();
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
|
|
|
|
|
return this.http.get<Pin>(url, { headers });
|
|
|
|
|
return this.http.get<Pin>(`${this.apiURL}/pin/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPins(): any {
|
|
|
|
|
const url = `${this.apiURL}/pins`;
|
|
|
|
|
const headers = this.authService.getAuthHeaders();
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
|
|
|
|
|
return this.http.get<any>(url, { headers });
|
|
|
|
|
return this.http.get<any>(`${this.apiURL}/pins`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addPin(pin: Pin) {
|
|
|
|
|
const url = `${this.apiURL}/pin/add`;
|
|
|
|
|
const headers = this.authService.getAuthHeaders();
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
|
|
|
|
|
return this.http.post<any>(url, pin, { headers });
|
|
|
|
|
return this.http.post<any>(`${this.apiURL}/pin/add`, pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatePin(id: string, pin: Pin) {
|
|
|
|
|
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, pin, { headers });
|
|
|
|
|
return this.http.patch<any>(`${this.apiURL}/pin/${id}`, pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deletePin(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 });
|
|
|
|
|
return this.http.delete<any>(`${this.apiURL}/pin/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sharePin(pinId: string, friendId: string) {
|
|
|
|
|
const url = `${this.apiURL}/pin/${pinId}/share`;
|
|
|
|
|
const headers = this.authService.getAuthHeaders();
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
|
|
|
|
|
return this.http.post<any>(url, { friend_id: friendId }, { headers });
|
|
|
|
|
return this.http.post<any>(`${this.apiURL}/pin/${pinId}/share`, { friend_id: friendId });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPinShares(pinId: string) {
|
|
|
|
|
const url = `${this.apiURL}/pin/${pinId}/shares`;
|
|
|
|
|
const headers = this.authService.getAuthHeaders();
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
return this.http.get<any>(url, { headers });
|
|
|
|
|
return this.http.get<any>(`${this.apiURL}/pin/${pinId}/shares`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSharedUsersForPin(pinId: string) {
|
|
|
|
|
const url = `${this.apiURL}/pin/${pinId}/shares`;
|
|
|
|
|
const headers = this.authService.getAuthHeaders();
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
|
|
|
|
|
// On retourne la liste directe des partages (utilisateurs avec qui le pin est partagé)
|
|
|
|
|
return this.http.get<{ shares: any[] }>(url, { headers }).pipe(
|
|
|
|
|
map((response) => response.shares) // Ne garder que la liste d’utilisateurs
|
|
|
|
|
return this.http.get<{ shares: any[] }>(`${this.apiURL}/pin/${pinId}/shares`).pipe(
|
|
|
|
|
map((response) => response.shares)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deletePinShare(pinId: string, friendId: string) {
|
|
|
|
|
const url = `${this.apiURL}/pin/${pinId}/share/${friendId}`;
|
|
|
|
|
const headers = this.authService.getAuthHeaders();
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
return this.http.delete<any>(url, { headers });
|
|
|
|
|
return this.http.delete<any>(`${this.apiURL}/pin/${pinId}/share/${friendId}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|