]>
Commit | Line | Data |
---|---|---|
1 | import { catchError, map } from 'rxjs/operators' | |
2 | import { HttpClient, HttpParams } from '@angular/common/http' | |
3 | import { Injectable } from '@angular/core' | |
4 | import { environment } from '../../../environments/environment' | |
5 | import { RestExtractor, RestService } from '../rest' | |
6 | import { VideoChangeOwnershipCreate } from '../../../../../shared/models/videos' | |
7 | import { Observable } from 'rxjs/index' | |
8 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
9 | import { ResultList, VideoChangeOwnership } from '../../../../../shared' | |
10 | import { RestPagination } from '@app/shared/rest' | |
11 | import { VideoChangeOwnershipAccept } from '../../../../../shared/models/videos/video-change-ownership-accept.model' | |
12 | ||
13 | @Injectable() | |
14 | export class VideoOwnershipService { | |
15 | private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/' | |
16 | ||
17 | constructor ( | |
18 | private authHttp: HttpClient, | |
19 | private restService: RestService, | |
20 | private restExtractor: RestExtractor | |
21 | ) { | |
22 | } | |
23 | ||
24 | changeOwnership (id: number, username: string) { | |
25 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership' | |
26 | const body: VideoChangeOwnershipCreate = { | |
27 | username | |
28 | } | |
29 | ||
30 | return this.authHttp.post(url, body) | |
31 | .pipe( | |
32 | map(this.restExtractor.extractDataBool), | |
33 | catchError(res => this.restExtractor.handleError(res)) | |
34 | ) | |
35 | } | |
36 | ||
37 | getOwnershipChanges (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoChangeOwnership>> { | |
38 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership' | |
39 | ||
40 | let params = new HttpParams() | |
41 | params = this.restService.addRestGetParams(params, pagination, sort) | |
42 | ||
43 | return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params }) | |
44 | .pipe( | |
45 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | |
46 | catchError(res => this.restExtractor.handleError(res)) | |
47 | ) | |
48 | } | |
49 | ||
50 | acceptOwnership (id: number, input: VideoChangeOwnershipAccept) { | |
51 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept' | |
52 | return this.authHttp.post(url, input) | |
53 | .pipe( | |
54 | map(this.restExtractor.extractDataBool), | |
55 | catchError(this.restExtractor.handleError) | |
56 | ) | |
57 | } | |
58 | ||
59 | refuseOwnership (id: number) { | |
60 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse' | |
61 | return this.authHttp.post(url, {}) | |
62 | .pipe( | |
63 | map(this.restExtractor.extractDataBool), | |
64 | catchError(this.restExtractor.handleError) | |
65 | ) | |
66 | } | |
67 | } |