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

master
parent d7283bcf20
commit b28033ae33

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

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

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

@ -17,76 +17,41 @@ export class PinService {
constructor(private http: HttpClient, private authService: AuthService) {} constructor(private http: HttpClient, private authService: AuthService) {}
getPinById(id: string) { getPinById(id: string) {
const url = `${this.apiURL}/pin/${id}`; return this.http.get<Pin>(`${this.apiURL}/pin/${id}`);
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.get<Pin>(url, { headers });
} }
getPins(): any { getPins(): any {
const url = `${this.apiURL}/pins`; return this.http.get<any>(`${this.apiURL}/pins`);
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.get<any>(url, { headers });
} }
addPin(pin: Pin) { addPin(pin: Pin) {
const url = `${this.apiURL}/pin/add`; return this.http.post<any>(`${this.apiURL}/pin/add`, pin);
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.post<any>(url, pin, { headers });
} }
updatePin(id: string, pin: 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 // 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) { deletePin(id: string) {
const url = `${this.apiURL}/pin/${id}`; return this.http.delete<any>(`${this.apiURL}/pin/${id}`);
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.delete<any>(url, { headers });
} }
sharePin(pinId: string, friendId: string) { sharePin(pinId: string, friendId: string) {
const url = `${this.apiURL}/pin/${pinId}/share`; return this.http.post<any>(`${this.apiURL}/pin/${pinId}/share`, { friend_id: friendId });
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.post<any>(url, { friend_id: friendId }, { headers });
} }
getPinShares(pinId: string) { getPinShares(pinId: string) {
const url = `${this.apiURL}/pin/${pinId}/shares`; return this.http.get<any>(`${this.apiURL}/pin/${pinId}/shares`);
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.get<any>(url, { headers });
} }
getSharedUsersForPin(pinId: string) { getSharedUsersForPin(pinId: string) {
const url = `${this.apiURL}/pin/${pinId}/shares`; return this.http.get<{ shares: any[] }>(`${this.apiURL}/pin/${pinId}/shares`).pipe(
const headers = this.authService.getAuthHeaders(); map((response) => response.shares)
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
); );
} }
deletePinShare(pinId: string, friendId: string) { deletePinShare(pinId: string, friendId: string) {
const url = `${this.apiURL}/pin/${pinId}/share/${friendId}`; return this.http.delete<any>(`${this.apiURL}/pin/${pinId}/share/${friendId}`);
const headers = this.authService.getAuthHeaders();
headers.set('Content-Type', 'application/json');
return this.http.delete<any>(url, { headers });
} }
} }

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

Loading…
Cancel
Save