]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/shared/follow.service.ts
Add follow tabs
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / shared / follow.service.ts
CommitLineData
df98563e 1import { Injectable } from '@angular/core'
8a02bd04
C
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Observable } from 'rxjs/Observable'
df98563e
C
4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'
e2f555ca 6
8a02bd04
C
7import { SortMeta } from 'primeng/primeng'
8
9import { RestExtractor, RestPagination, RestService } from '../../../shared'
d592e0a9 10import { Pod, ResultList } from '../../../../../../shared'
e2f555ca
C
11
12@Injectable()
51548b31
C
13export class FollowService {
14 private static BASE_APPLICATION_URL = API_URL + '/api/v1/application'
e2f555ca
C
15
16 constructor (
d592e0a9 17 private authHttp: HttpClient,
8a02bd04 18 private restService: RestService,
de59c48f 19 private restExtractor: RestExtractor
e2f555ca
C
20 ) {}
21
1e1265b3 22 getFollowing (pagination: RestPagination, sort: SortMeta): Observable<ResultList<Pod>> {
8a02bd04
C
23 let params = new HttpParams()
24 params = this.restService.addRestGetParams(params, pagination, sort)
25
51548b31 26 return this.authHttp.get<ResultList<Account>>(FollowService.BASE_APPLICATION_URL + '/following', { params })
d592e0a9
C
27 .map(res => this.restExtractor.convertResultListDateToHuman(res))
28 .catch(res => this.restExtractor.handleError(res))
e2f555ca
C
29 }
30
51548b31
C
31 getFollowers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<Pod>> {
32 let params = new HttpParams()
33 params = this.restService.addRestGetParams(params, pagination, sort)
34
35 return this.authHttp.get<ResultList<Account>>(FollowService.BASE_APPLICATION_URL + '/followers', { params })
36 .map(res => this.restExtractor.convertResultListDateToHuman(res))
37 .catch(res => this.restExtractor.handleError(res))
38 }
39
1e1265b3 40 follow (notEmptyHosts: String[]) {
e105c19c 41 const body = {
49abbbbe 42 hosts: notEmptyHosts
df98563e 43 }
e105c19c 44
51548b31 45 return this.authHttp.post(FollowService.BASE_APPLICATION_URL + '/follow', body)
d5f5a670 46 .map(this.restExtractor.extractDataBool)
d592e0a9 47 .catch(res => this.restExtractor.handleError(res))
d5f5a670 48 }
e2f555ca 49}