aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/friends/shared/friend.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin/friends/shared/friend.service.ts')
-rw-r--r--client/src/app/+admin/friends/shared/friend.service.ts47
1 files changed, 47 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..e97459385
--- /dev/null
+++ b/client/src/app/+admin/friends/shared/friend.service.ts
@@ -0,0 +1,47 @@
1import { Injectable } from '@angular/core';
2import { Observable } from 'rxjs/Observable';
3import 'rxjs/add/operator/catch';
4import 'rxjs/add/operator/map';
5
6import { Friend } from './friend.model';
7import { AuthHttp, RestExtractor, ResultList } from '../../../shared';
8
9@Injectable()
10export class FriendService {
11 private static BASE_FRIEND_URL: string = '/api/v1/pods/';
12
13 constructor (
14 private authHttp: AuthHttp,
15 private restExtractor: RestExtractor
16 ) {}
17
18 getFriends() {
19 return this.authHttp.get(FriendService.BASE_FRIEND_URL)
20 .map(this.restExtractor.extractDataList)
21 .map(this.extractFriends)
22 .catch((res) => this.restExtractor.handleError(res));
23 }
24
25 makeFriends(notEmptyHosts) {
26 const body = {
27 hosts: notEmptyHosts
28 };
29
30 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
31 .map(this.restExtractor.extractDataBool)
32 .catch((res) => this.restExtractor.handleError(res));
33 }
34
35 quitFriends() {
36 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
37 .map(res => res.status)
38 .catch((res) => this.restExtractor.handleError(res));
39 }
40
41 private extractFriends(result: ResultList) {
42 const friends: Friend[] = result.data;
43 const totalFriends = result.total;
44
45 return { friends, totalFriends };
46 }
47}