]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/admin/friends/shared/friend.service.ts
Update readme
[github/Chocobozzz/PeerTube.git] / client / src / app / admin / friends / shared / friend.service.ts
CommitLineData
e2f555ca 1import { Injectable } from '@angular/core';
e2f555ca
C
2import { Observable } from 'rxjs/Observable';
3
4import { Friend } from './friend.model';
55fa55a9 5import { AuthHttp, RestExtractor, ResultList } from '../../../shared';
e2f555ca
C
6
7@Injectable()
8export 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
55fa55a9 16 getFriends() {
e2f555ca 17 return this.authHttp.get(FriendService.BASE_FRIEND_URL)
55fa55a9
C
18 .map(this.restExtractor.extractDataList)
19 .map(this.extractFriends)
de59c48f 20 .catch((res) => this.restExtractor.handleError(res));
e2f555ca
C
21 }
22
49abbbbe 23 makeFriends(notEmptyHosts) {
e105c19c 24 const body = {
49abbbbe 25 hosts: notEmptyHosts
e105c19c
C
26 };
27
28 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
de59c48f
C
29 .map(this.restExtractor.extractDataBool)
30 .catch((res) => this.restExtractor.handleError(res));
e2f555ca
C
31 }
32
33 quitFriends() {
34 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
35 .map(res => res.status)
de59c48f 36 .catch((res) => this.restExtractor.handleError(res));
e2f555ca 37 }
55fa55a9
C
38
39 private extractFriends(result: ResultList) {
40 const friends: Friend[] = result.data;
41 const totalFriends = result.total;
42
43 return { friends, totalFriends };
44 }
e2f555ca 45}