]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video/video-ownership.service.ts
Fix avatar default size
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video-ownership.service.ts
CommitLineData
67ed6552
C
1import { SortMeta } from 'primeng/api'
2import { Observable } from 'rxjs'
74d63469
GR
3import { catchError, map } from 'rxjs/operators'
4import { HttpClient, HttpParams } from '@angular/common/http'
5import { Injectable } from '@angular/core'
67ed6552
C
6import { RestExtractor, RestPagination, RestService } from '@app/core'
7import { ResultList, VideoChangeOwnership, VideoChangeOwnershipAccept, VideoChangeOwnershipCreate } from '@shared/models'
8import { environment } from '../../../../environments/environment'
74d63469
GR
9
10@Injectable()
11export 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)
e8bffe96 28 .pipe(catchError(res => this.restExtractor.handleError(res)))
74d63469
GR
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(
39 map(res => this.restExtractor.convertResultListDateToHuman(res)),
40 catchError(res => this.restExtractor.handleError(res))
41 )
42 }
43
44 acceptOwnership (id: number, input: VideoChangeOwnershipAccept) {
45 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept'
46 return this.authHttp.post(url, input)
e8bffe96 47 .pipe(catchError(this.restExtractor.handleError))
74d63469
GR
48 }
49
50 refuseOwnership (id: number) {
51 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse'
52 return this.authHttp.post(url, {})
e8bffe96 53 .pipe(catchError(this.restExtractor.handleError))
74d63469
GR
54 }
55}