]>
Commit | Line | Data |
---|---|---|
e2f555ca | 1 | import { Injectable } from '@angular/core'; |
e2f555ca C |
2 | import { Observable } from 'rxjs/Observable'; |
3 | ||
4 | import { Friend } from './friend.model'; | |
de59c48f | 5 | import { AuthHttp, RestExtractor } from '../../../shared'; |
e2f555ca C |
6 | |
7 | @Injectable() | |
8 | export class FriendService { | |
9 | private static BASE_FRIEND_URL: string = '/api/v1/pods/'; | |
10 | ||
11 | constructor ( | |
12 | private authHttp: AuthHttp, | |
de59c48f | 13 | private restExtractor: RestExtractor |
e2f555ca C |
14 | ) {} |
15 | ||
16 | getFriends(): Observable<Friend[]> { | |
17 | return this.authHttp.get(FriendService.BASE_FRIEND_URL) | |
de59c48f C |
18 | // Not implemented as a data list by the server yet |
19 | // .map(this.restExtractor.extractDataList) | |
20 | .map((res) => res.json()) | |
21 | .catch((res) => this.restExtractor.handleError(res)); | |
e2f555ca C |
22 | } |
23 | ||
e105c19c C |
24 | makeFriends(notEmptyUrls) { |
25 | const body = { | |
26 | urls: notEmptyUrls | |
27 | }; | |
28 | ||
29 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) | |
de59c48f C |
30 | .map(this.restExtractor.extractDataBool) |
31 | .catch((res) => this.restExtractor.handleError(res)); | |
e2f555ca C |
32 | } |
33 | ||
34 | quitFriends() { | |
35 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') | |
36 | .map(res => res.status) | |
de59c48f | 37 | .catch((res) => this.restExtractor.handleError(res)); |
e2f555ca C |
38 | } |
39 | } |