]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/video/video-ownership.service.ts
Update angular
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video-ownership.service.ts
1 import { SortMeta } from 'primeng/api'
2 import { Observable } from 'rxjs'
3 import { catchError } from 'rxjs/operators'
4 import { HttpClient, HttpParams } from '@angular/common/http'
5 import { Injectable } from '@angular/core'
6 import { RestExtractor, RestPagination, RestService } from '@app/core'
7 import { ResultList, VideoChangeOwnership, VideoChangeOwnershipAccept, VideoChangeOwnershipCreate } from '@shared/models'
8 import { environment } from '../../../../environments/environment'
9
10 @Injectable()
11 export class VideoOwnershipService {
12 private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/'
13
14 constructor (
15 private authHttp: HttpClient,
16 private restService: RestService,
17 private restExtractor: RestExtractor
18 ) {
19 }
20
21 changeOwnership (id: number, username: string) {
22 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership'
23 const body: VideoChangeOwnershipCreate = {
24 username
25 }
26
27 return this.authHttp.post(url, body)
28 .pipe(catchError(res => this.restExtractor.handleError(res)))
29 }
30
31 getOwnershipChanges (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoChangeOwnership>> {
32 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership'
33
34 let params = new HttpParams()
35 params = this.restService.addRestGetParams(params, pagination, sort)
36
37 return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params })
38 .pipe(catchError(res => this.restExtractor.handleError(res)))
39 }
40
41 acceptOwnership (id: number, input: VideoChangeOwnershipAccept) {
42 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept'
43 return this.authHttp.post(url, input)
44 .pipe(catchError(this.restExtractor.handleError))
45 }
46
47 refuseOwnership (id: number) {
48 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse'
49 return this.authHttp.post(url, {})
50 .pipe(catchError(this.restExtractor.handleError))
51 }
52 }