]>
Commit | Line | Data |
---|---|---|
1 | import { HttpClient, HttpParams } from '@angular/common/http' | |
2 | import { Injectable } from '@angular/core' | |
3 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
4 | import 'rxjs/add/operator/catch' | |
5 | import 'rxjs/add/operator/map' | |
6 | import { Observable } from 'rxjs/Observable' | |
7 | import { BlacklistedVideo, ResultList } from '../../../../../shared' | |
8 | import { environment } from '../../../environments/environment' | |
9 | import { RestExtractor, RestPagination, RestService } from '../rest' | |
10 | ||
11 | @Injectable() | |
12 | export class VideoBlacklistService { | |
13 | private static BASE_VIDEOS_URL = environment.apiUrl + '/api/v1/videos/' | |
14 | ||
15 | constructor ( | |
16 | private authHttp: HttpClient, | |
17 | private restService: RestService, | |
18 | private restExtractor: RestExtractor | |
19 | ) {} | |
20 | ||
21 | listBlacklist (pagination: RestPagination, sort: SortMeta): Observable<ResultList<BlacklistedVideo>> { | |
22 | let params = new HttpParams() | |
23 | params = this.restService.addRestGetParams(params, pagination, sort) | |
24 | ||
25 | return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) | |
26 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) | |
27 | .catch(res => this.restExtractor.handleError(res)) | |
28 | } | |
29 | ||
30 | removeVideoFromBlacklist (videoId: number) { | |
31 | return this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist') | |
32 | .map(this.restExtractor.extractDataBool) | |
33 | .catch(res => this.restExtractor.handleError(res)) | |
34 | } | |
35 | ||
36 | blacklistVideo (videoId: number) { | |
37 | return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', {}) | |
38 | .map(this.restExtractor.extractDataBool) | |
39 | .catch(res => this.restExtractor.handleError(res)) | |
40 | } | |
41 | } |