]>
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' | |
d592e0a9 | 10 | import { Pod, ResultList } from '../../../../../../shared' |
e2f555ca C |
11 | |
12 | @Injectable() | |
13 | export class FriendService { | |
df98563e | 14 | private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/' |
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 | ||
350e31d6 | 26 | return this.authHttp.get<ResultList<Account>>(API_URL + '/api/v1/pods/followers', { params }) |
d592e0a9 C |
27 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) |
28 | .catch(res => this.restExtractor.handleError(res)) | |
e2f555ca C |
29 | } |
30 | ||
1e1265b3 | 31 | follow (notEmptyHosts: String[]) { |
e105c19c | 32 | const body = { |
49abbbbe | 33 | hosts: notEmptyHosts |
df98563e | 34 | } |
e105c19c | 35 | |
350e31d6 | 36 | return this.authHttp.post(API_URL + '/api/v1/pods/follow', body) |
de59c48f | 37 | .map(this.restExtractor.extractDataBool) |
d592e0a9 | 38 | .catch(res => this.restExtractor.handleError(res)) |
e2f555ca C |
39 | } |
40 | ||
df98563e | 41 | quitFriends () { |
aa2e7f15 | 42 | return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quit-friends') |
d592e0a9 C |
43 | .map(this.restExtractor.extractDataBool) |
44 | .catch(res => this.restExtractor.handleError(res)) | |
e2f555ca | 45 | } |
d5f5a670 GS |
46 | |
47 | removeFriend (friend: Pod) { | |
48 | return this.authHttp.delete(FriendService.BASE_FRIEND_URL + friend.id) | |
49 | .map(this.restExtractor.extractDataBool) | |
d592e0a9 | 50 | .catch(res => this.restExtractor.handleError(res)) |
d5f5a670 | 51 | } |
e2f555ca | 52 | } |