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