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'
11 export class VideoOwnershipService {
12 private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/'
15 private authHttp: HttpClient,
16 private restService: RestService,
17 private restExtractor: RestExtractor
21 changeOwnership (id: number, username: string) {
22 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership'
23 const body: VideoChangeOwnershipCreate = {
27 return this.authHttp.post(url, body)
28 .pipe(catchError(res => this.restExtractor.handleError(res)))
31 getOwnershipChanges (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoChangeOwnership>> {
32 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership'
34 let params = new HttpParams()
35 params = this.restService.addRestGetParams(params, pagination, sort)
37 return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params })
38 .pipe(catchError(res => this.restExtractor.handleError(res)))
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))
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))