]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Injectable } from '@angular/core' |
d592e0a9 | 2 | import { HttpClient } from '@angular/common/http' |
df98563e C |
3 | import 'rxjs/add/operator/catch' |
4 | import 'rxjs/add/operator/map' | |
e2f555ca | 5 | |
d5050d1e | 6 | import { RestExtractor } from '../../../shared' |
d592e0a9 | 7 | import { Pod, ResultList } from '../../../../../../shared' |
e2f555ca C |
8 | |
9 | @Injectable() | |
10 | export class FriendService { | |
df98563e | 11 | private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/' |
e2f555ca C |
12 | |
13 | constructor ( | |
d592e0a9 | 14 | private authHttp: HttpClient, |
de59c48f | 15 | private restExtractor: RestExtractor |
e2f555ca C |
16 | ) {} |
17 | ||
d592e0a9 C |
18 | getFriends () { |
19 | return this.authHttp.get<ResultList<Pod>>(FriendService.BASE_FRIEND_URL) | |
20 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) | |
21 | .catch(res => this.restExtractor.handleError(res)) | |
e2f555ca C |
22 | } |
23 | ||
d5f5a670 | 24 | makeFriends (notEmptyHosts: String[]) { |
e105c19c | 25 | const body = { |
49abbbbe | 26 | hosts: notEmptyHosts |
df98563e | 27 | } |
e105c19c | 28 | |
aa2e7f15 | 29 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'make-friends', body) |
de59c48f | 30 | .map(this.restExtractor.extractDataBool) |
d592e0a9 | 31 | .catch(res => this.restExtractor.handleError(res)) |
e2f555ca C |
32 | } |
33 | ||
df98563e | 34 | quitFriends () { |
aa2e7f15 | 35 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quit-friends') |
d592e0a9 C |
36 | .map(this.restExtractor.extractDataBool) |
37 | .catch(res => this.restExtractor.handleError(res)) | |
e2f555ca | 38 | } |
d5f5a670 GS |
39 | |
40 | removeFriend (friend: Pod) { | |
41 | return this.authHttp.delete(FriendService.BASE_FRIEND_URL + friend.id) | |
42 | .map(this.restExtractor.extractDataBool) | |
d592e0a9 | 43 | .catch(res => this.restExtractor.handleError(res)) |
d5f5a670 | 44 | } |
e2f555ca | 45 | } |