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