diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/shared-main/video/video-ownership.service.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/shared-main/video/video-ownership.service.ts')
-rw-r--r-- | client/src/app/shared/shared-main/video/video-ownership.service.ts | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/video/video-ownership.service.ts b/client/src/app/shared/shared-main/video/video-ownership.service.ts new file mode 100644 index 000000000..273930a6c --- /dev/null +++ b/client/src/app/shared/shared-main/video/video-ownership.service.ts | |||
@@ -0,0 +1,64 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { Observable } from 'rxjs' | ||
3 | import { catchError, map } 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( | ||
29 | map(this.restExtractor.extractDataBool), | ||
30 | catchError(res => this.restExtractor.handleError(res)) | ||
31 | ) | ||
32 | } | ||
33 | |||
34 | getOwnershipChanges (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoChangeOwnership>> { | ||
35 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership' | ||
36 | |||
37 | let params = new HttpParams() | ||
38 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
39 | |||
40 | return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params }) | ||
41 | .pipe( | ||
42 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
43 | catchError(res => this.restExtractor.handleError(res)) | ||
44 | ) | ||
45 | } | ||
46 | |||
47 | acceptOwnership (id: number, input: VideoChangeOwnershipAccept) { | ||
48 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept' | ||
49 | return this.authHttp.post(url, input) | ||
50 | .pipe( | ||
51 | map(this.restExtractor.extractDataBool), | ||
52 | catchError(this.restExtractor.handleError) | ||
53 | ) | ||
54 | } | ||
55 | |||
56 | refuseOwnership (id: number) { | ||
57 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse' | ||
58 | return this.authHttp.post(url, {}) | ||
59 | .pipe( | ||
60 | map(this.restExtractor.extractDataBool), | ||
61 | catchError(this.restExtractor.handleError) | ||
62 | ) | ||
63 | } | ||
64 | } | ||