]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Injectable } from '@angular/core' |
8a02bd04 C |
2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Observable } from 'rxjs/Observable' | |
df98563e C |
4 | import 'rxjs/add/operator/catch' |
5 | import 'rxjs/add/operator/map' | |
e2f555ca | 6 | |
8a02bd04 C |
7 | import { SortMeta } from 'primeng/primeng' |
8 | ||
9 | import { RestExtractor, RestPagination, RestService } from '../../../shared' | |
60862425 | 10 | import { AccountFollow, ResultList } from '../../../../../../shared' |
e2f555ca C |
11 | |
12 | @Injectable() | |
51548b31 C |
13 | export 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 | ||
60862425 | 22 | getFollowing (pagination: RestPagination, sort: SortMeta): Observable<ResultList<AccountFollow>> { |
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 | ||
60862425 | 31 | getFollowers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<AccountFollow>> { |
51548b31 C |
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 | } |