]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/shared/video-blacklist/video-blacklist.service.ts
Upgrade Angular first step
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-blacklist / video-blacklist.service.ts
... / ...
CommitLineData
1import { HttpClient, HttpParams } from '@angular/common/http'
2import { Injectable } from '@angular/core'
3import { SortMeta } from 'primeng/components/common/sortmeta'
4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'
6import { Observable } from 'rxjs/Observable'
7import { BlacklistedVideo, ResultList } from '../../../../../shared'
8import { environment } from '../../../environments/environment'
9import { RestExtractor, RestPagination, RestService } from '../rest'
10
11@Injectable()
12export 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}