You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { map } from 'rxjs/operators';
|
|
import { environment } from '../../../environment';
|
|
import { Pin } from '../../model/Pin';
|
|
import { AuthService } from '../auth/auth.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class PinService {
|
|
allPins: Pin[] = [];
|
|
filteredPins: Pin[] = [];
|
|
|
|
private apiURL = environment.apiURL;
|
|
|
|
constructor(private http: HttpClient, private authService: AuthService) {}
|
|
|
|
getPinById(id: string) {
|
|
return this.http.get<Pin>(`${this.apiURL}/pin/${id}`);
|
|
}
|
|
|
|
getPins(): any {
|
|
return this.http.get<any>(`${this.apiURL}/pins`);
|
|
}
|
|
|
|
addPin(pin: Pin) {
|
|
return this.http.post<any>(`${this.apiURL}/pin/add`, pin);
|
|
}
|
|
|
|
updatePin(id: string, pin: Pin) {
|
|
// Obtenir les coordonnées GPS à partir de l'adresse
|
|
return this.http.patch<any>(`${this.apiURL}/pin/${id}`, pin);
|
|
}
|
|
|
|
deletePin(id: string) {
|
|
return this.http.delete<any>(`${this.apiURL}/pin/${id}`);
|
|
}
|
|
|
|
sharePin(pinId: string, friendId: string) {
|
|
return this.http.post<any>(`${this.apiURL}/pin/${pinId}/share`, { friend_id: friendId });
|
|
}
|
|
|
|
getPinShares(pinId: string) {
|
|
return this.http.get<any>(`${this.apiURL}/pin/${pinId}/shares`);
|
|
}
|
|
|
|
getSharedUsersForPin(pinId: string) {
|
|
return this.http.get<{ shares: any[] }>(`${this.apiURL}/pin/${pinId}/shares`).pipe(
|
|
map((response) => response.shares)
|
|
);
|
|
}
|
|
|
|
deletePinShare(pinId: string, friendId: string) {
|
|
return this.http.delete<any>(`${this.apiURL}/pin/${pinId}/share/${friendId}`);
|
|
}
|
|
}
|