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.
60 lines
1.8 KiB
60 lines
1.8 KiB
import { Injectable, OnInit } from '@angular/core';
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
import { environment } from '../../../environments/environment';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class FriendsService {
|
|
|
|
private apiURL = environment.apiURL;
|
|
constructor(private http: HttpClient) {
|
|
}
|
|
|
|
getFriend() {
|
|
console.log("getFriends");
|
|
const url = `${this.apiURL}/friends`;
|
|
const headers = new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
});
|
|
return this.http.get<any[]>(url, { headers });
|
|
}
|
|
|
|
getFriendById(id: string) {
|
|
const url = `${this.apiURL}/user/${id}`;
|
|
const headers = new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
});
|
|
return this.http.get<any>(url, { headers });
|
|
}
|
|
|
|
acceptFriendById(id: string){
|
|
const url = `${this.apiURL}/friend/${id}/accept`;
|
|
const headers = new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
});
|
|
return this.http.patch<any>(url, [], { headers });
|
|
}
|
|
|
|
denyFriendById(id: string){
|
|
const url = `${this.apiURL}/friend/${id}/deny`;
|
|
const headers = new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
});
|
|
return this.http.delete<any>(url, { headers });
|
|
}
|
|
|
|
deleteFriend(id: string){
|
|
const url = `${this.apiURL}/friend/${id}/delete`;
|
|
const headers = new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
});
|
|
return this.http.delete<any>(url, { headers });
|
|
}
|
|
}
|