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