From b28033ae338e90cd3ac7c7e8bbeb280e8d5eab39 Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Thu, 19 Jun 2025 00:50:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Simplified=20HTTP=20calls=20to?= =?UTF-8?q?=20services=20by=20removing=20redundant=20authentication=20head?= =?UTF-8?q?ers.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/components/navbar/navbar.component.ts | 1 - src/app/services/friends/friends.service.ts | 36 ++---------- src/app/services/image/image.service.ts | 15 +---- src/app/services/pin/pin.service.ts | 55 ++++--------------- src/app/services/user/user.service.ts | 12 +--- 5 files changed, 21 insertions(+), 98 deletions(-) diff --git a/src/app/components/navbar/navbar.component.ts b/src/app/components/navbar/navbar.component.ts index 41195a3..44d39cc 100644 --- a/src/app/components/navbar/navbar.component.ts +++ b/src/app/components/navbar/navbar.component.ts @@ -168,6 +168,5 @@ export class NavbarComponent implements OnInit { public logout() { this.authService.logout(); - this.router.navigate(['/']); } } diff --git a/src/app/services/friends/friends.service.ts b/src/app/services/friends/friends.service.ts index 527fd82..728a244 100644 --- a/src/app/services/friends/friends.service.ts +++ b/src/app/services/friends/friends.service.ts @@ -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(url, { headers }); + return this.http.get(`${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(url, { headers }); + return this.http.get(`${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(url, { friend_user_id: user_id }, { headers }); + return this.http.post(`${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(url, [], { headers }); + return this.http.patch(`${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(url, { headers }); + return this.http.delete(`${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(url, { headers }); + return this.http.delete(`${this.apiURL}/friend/${id}/delete`); } } diff --git a/src/app/services/image/image.service.ts b/src/app/services/image/image.service.ts index 3267014..b6b03c8 100644 --- a/src/app/services/image/image.service.ts +++ b/src/app/services/image/image.service.ts @@ -16,19 +16,12 @@ export class ImageService { ) { } getImage(imageId: string): Observable { - 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 { 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 { - const headers = this.authService.getAuthHeaders(); - - return this.http.get(`${this.apiUrl}/image/${imageId}/metadata`, { headers }); + return this.http.get(`${this.apiUrl}/image/${imageId}/metadata`); } } \ No newline at end of file diff --git a/src/app/services/pin/pin.service.ts b/src/app/services/pin/pin.service.ts index eb68276..1b48210 100644 --- a/src/app/services/pin/pin.service.ts +++ b/src/app/services/pin/pin.service.ts @@ -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(url, { headers }); + return this.http.get(`${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(url, { headers }); + return this.http.get(`${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(url, pin, { headers }); + return this.http.post(`${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(url, pin, { headers }); + return this.http.patch(`${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(url, { headers }); + return this.http.delete(`${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(url, { friend_id: friendId }, { headers }); + return this.http.post(`${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(url, { headers }); + return this.http.get(`${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(url, { headers }); + return this.http.delete(`${this.apiURL}/pin/${pinId}/share/${friendId}`); } } diff --git a/src/app/services/user/user.service.ts b/src/app/services/user/user.service.ts index 4bcf9a8..c1a0c91 100644 --- a/src/app/services/user/user.service.ts +++ b/src/app/services/user/user.service.ts @@ -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(url, { headers: headers, params: params }); + return this.http.get(`${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(url, { headers }); + return this.http.get(`${this.apiURL}/user/${userId}`); } }