]>
Commit | Line | Data |
---|---|---|
1 | import { Injectable } from '@angular/core'; | |
2 | import { Observable } from 'rxjs/Observable'; | |
3 | import 'rxjs/add/operator/catch'; | |
4 | import 'rxjs/add/operator/map'; | |
5 | ||
6 | import { ServerDataSource } from 'ng2-smart-table'; | |
7 | ||
8 | import { Friend } from './friend.model'; | |
9 | import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared'; | |
10 | ||
11 | @Injectable() | |
12 | export class FriendService { | |
13 | private static BASE_FRIEND_URL: string = '/api/v1/pods/'; | |
14 | ||
15 | constructor ( | |
16 | private authHttp: AuthHttp, | |
17 | private restExtractor: RestExtractor | |
18 | ) {} | |
19 | ||
20 | getDataSource() { | |
21 | return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL); | |
22 | } | |
23 | ||
24 | makeFriends(notEmptyHosts) { | |
25 | const body = { | |
26 | hosts: notEmptyHosts | |
27 | }; | |
28 | ||
29 | return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) | |
30 | .map(this.restExtractor.extractDataBool) | |
31 | .catch((res) => this.restExtractor.handleError(res)); | |
32 | } | |
33 | ||
34 | quitFriends() { | |
35 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') | |
36 | .map(res => res.status) | |
37 | .catch((res) => this.restExtractor.handleError(res)); | |
38 | } | |
39 | } |