🔧 Simplified HTTP calls to services by removing redundant authentication headers.
continuous-integration/drone/push Build is passing Details

master
Alix JEUDI--LEMOINE 24 hours ago
parent d7283bcf20
commit b28033ae33

@ -168,6 +168,5 @@ export class NavbarComponent implements OnInit {
public logout() {
this.authService.logout();
this.router.navigate(['/']);
}
}

@ -11,50 +11,26 @@ export class FriendsService {
constructor(private http: HttpClient, private authService: AuthService) {}
getFriend() {
const url = `${this.apiURL}/friends`;
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}/friends`);
}
getFriendById(id: string) {
const url = `${this.apiURL}/user/${id}`;
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}/user/${id}`);
}
addFriend(user_id: string) {
const url = `${this.apiURL}/friend/add`;
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.post<any>(url, { friend_user_id: user_id }, { headers });
return this.http.post<any>(`${this.apiURL}/friend/add`, { friend_user_id: user_id });
}
acceptFriendById(id: string) {
const url = `${this.apiURL}/friend/${id}/accept`;
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.patch<any>(url, [], { headers });
return this.http.patch<any>(`${this.apiURL}/friend/${id}/accept`, []);
}
denyFriendById(id: string) {
const url = `${this.apiURL}/friend/${id}/deny`;
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}/friend/${id}/deny`);
}
deleteFriend(id: string) {
const url = `${this.apiURL}/friend/${id}/delete`;
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}/friend/${id}/delete`);
}
}

@ -16,19 +16,12 @@ export class ImageService {
) { }
getImage(imageId: string): Observable<Blob> {
const headers = this.authService.getAuthHeaders();
return this.http.get(`${this.apiUrl}/image/${imageId}`, {
headers,
responseType: 'blob'
});
return this.http.get(`${this.apiUrl}/image/${imageId}`, { responseType: 'blob' });
}
postImage(image: File, date: string): Observable<any> {
let url = `${this.apiUrl}/image/pin/null/add`;
const headers = this.authService.getAuthHeaders();
const formData = new FormData();
formData.append('image', image);
@ -36,12 +29,10 @@ export class ImageService {
url += `?exif_date=${date}`;
}
return this.http.post(url, formData, { headers });
return this.http.post(url, formData);
}
getImageMetadata(imageId: string): Observable<any> {
const headers = this.authService.getAuthHeaders();
return this.http.get(`${this.apiUrl}/image/${imageId}/metadata`, { headers });
return this.http.get(`${this.apiUrl}/image/${imageId}/metadata`);
}
}

@ -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 dutilisateurs
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}`);
}
}

@ -11,20 +11,12 @@ export class UserService {
constructor(private http: HttpClient, private authService: AuthService) {}
getUser(username: string) {
const url = `${this.apiURL}/users`;
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
const params = { name: username };
return this.http.get<any[]>(url, { headers: headers, params: params });
return this.http.get<any[]>(`${this.apiURL}/users`, { params });
}
getUserById(userId: string) {
const url = `${this.apiURL}/user/${userId}`;
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}/user/${userId}`);
}
}

Loading…
Cancel
Save