diff --git a/src/app/components/friend-page/friend-page.component.ts b/src/app/components/friend-page/friend-page.component.ts
index b5b51c0..8ca9b57 100644
--- a/src/app/components/friend-page/friend-page.component.ts
+++ b/src/app/components/friend-page/friend-page.component.ts
@@ -1,24 +1,41 @@
-import { Component } from '@angular/core';
+import { Component, OnInit } from '@angular/core';
import { FriendsService } from '../../services/friends/friends.service';
-import { User } from '../../model/User';
+import { NgFor, NgIf } from '@angular/common';
@Component({
selector: 'app-friend-page',
- imports: [],
+ imports: [NgFor, NgIf],
templateUrl: './friend-page.component.html',
- styleUrl: './friend-page.component.css'
+ styleUrls: ['./friend-page.component.css']
})
-export class FriendPageComponent {
+export class FriendPageComponent implements OnInit {
+ listFriend: {username: string, status: string}[] = [];
+ userId: string = "";
+ status: string = "";
- private readonly listFriend : User[] = [];
- constructor(friendService : FriendsService){
- friendService.getFriend().subscribe((data) => {
- this.listFriend.push();
- });;
+ constructor(private friendService: FriendsService) {
}
-
-
-
+ ngOnInit(): void {
+ this.getFriendData();
+ console.log(this.listFriend)
+ }
+ private getFriendData(): void {
+ this.friendService.getFriend().subscribe((data: any[]) => {
+ if (data.length > 0) {
+ data.forEach(friend => {
+ let status = friend['status'];
+ let userId = friend['friend_user_id'];
+ this.friendService.getFriendById(userId).subscribe((friendData: any) => {
+ this.listFriend.push({
+ username: friendData.username,
+ status: status
+ });
+ });
+ });
+ }
+ });
+ }
+
}
diff --git a/src/app/services/friends/friends.service.ts b/src/app/services/friends/friends.service.ts
index cd759d9..4c1d6e2 100644
--- a/src/app/services/friends/friends.service.ts
+++ b/src/app/services/friends/friends.service.ts
@@ -11,16 +11,21 @@ export class FriendsService {
private token = localStorage.getItem('auth_token');
constructor(private http: HttpClient) { }
-
- getFriend(){
+ getFriend() {
const url = `${this.apiURL}/friends`;
const headers = new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.token,
});
- return this.http.get(url);
+ return this.http.get
(url, { headers });
}
-
-
+ getFriendById(id: string) {
+ const url = `${this.apiURL}/user/${id}`;
+ const headers = new HttpHeaders({
+ 'Content-Type': 'application/json',
+ Authorization: 'Bearer ' + this.token,
+ });
+ return this.http.get(url, { headers });
+ }
}