diff options
Diffstat (limited to 'client/src/app/admin/friends/shared/friend.service.ts')
-rw-r--r-- | client/src/app/admin/friends/shared/friend.service.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/client/src/app/admin/friends/shared/friend.service.ts b/client/src/app/admin/friends/shared/friend.service.ts new file mode 100644 index 000000000..da4d64611 --- /dev/null +++ b/client/src/app/admin/friends/shared/friend.service.ts | |||
@@ -0,0 +1,39 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Response } from '@angular/http'; | ||
3 | import { Observable } from 'rxjs/Observable'; | ||
4 | |||
5 | import { Friend } from './friend.model'; | ||
6 | import { AuthHttp, AuthService } from '../../../shared'; | ||
7 | |||
8 | @Injectable() | ||
9 | export class FriendService { | ||
10 | private static BASE_FRIEND_URL: string = '/api/v1/pods/'; | ||
11 | |||
12 | constructor ( | ||
13 | private authHttp: AuthHttp, | ||
14 | private authService: AuthService | ||
15 | ) {} | ||
16 | |||
17 | getFriends(): Observable<Friend[]> { | ||
18 | return this.authHttp.get(FriendService.BASE_FRIEND_URL) | ||
19 | .map(res => <Friend[]>res.json()) | ||
20 | .catch(this.handleError); | ||
21 | } | ||
22 | |||
23 | makeFriends() { | ||
24 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'makefriends') | ||
25 | .map(res => res.status) | ||
26 | .catch(this.handleError); | ||
27 | } | ||
28 | |||
29 | quitFriends() { | ||
30 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') | ||
31 | .map(res => res.status) | ||
32 | .catch(this.handleError); | ||
33 | } | ||
34 | |||
35 | private handleError (error: Response) { | ||
36 | console.error(error); | ||
37 | return Observable.throw(error.json().error || 'Server error'); | ||
38 | } | ||
39 | } | ||