]>
Commit | Line | Data |
---|---|---|
1 | import { SortMeta } from 'primeng/api' | |
2 | import { catchError, Observable } from 'rxjs' | |
3 | import { environment } from 'src/environments/environment' | |
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 } from '@shared/models/common' | |
8 | import { VideoChannelSync, VideoChannelSyncCreate } from '@shared/models/videos' | |
9 | import { Account, AccountService } from '../account' | |
10 | ||
11 | @Injectable({ | |
12 | providedIn: 'root' | |
13 | }) | |
14 | export class VideoChannelSyncService { | |
15 | static BASE_VIDEO_CHANNEL_URL = environment.apiUrl + '/api/v1/video-channel-syncs' | |
16 | ||
17 | constructor ( | |
18 | private authHttp: HttpClient, | |
19 | private restExtractor: RestExtractor, | |
20 | private restService: RestService | |
21 | ) { } | |
22 | ||
23 | listAccountVideoChannelsSyncs (parameters: { | |
24 | sort: SortMeta | |
25 | pagination: RestPagination | |
26 | account: Account | |
27 | }): Observable<ResultList<VideoChannelSync>> { | |
28 | const { pagination, sort, account } = parameters | |
29 | ||
30 | let params = new HttpParams() | |
31 | params = this.restService.addRestGetParams(params, pagination, sort) | |
32 | ||
33 | const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channel-syncs' | |
34 | ||
35 | return this.authHttp.get<ResultList<VideoChannelSync>>(url, { params }) | |
36 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
37 | } | |
38 | ||
39 | createSync (body: VideoChannelSyncCreate) { | |
40 | return this.authHttp.post<{ videoChannelSync: VideoChannelSync }>(VideoChannelSyncService.BASE_VIDEO_CHANNEL_URL, body) | |
41 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
42 | } | |
43 | ||
44 | deleteSync (videoChannelsSyncId: number) { | |
45 | const url = `${VideoChannelSyncService.BASE_VIDEO_CHANNEL_URL}/${videoChannelsSyncId}` | |
46 | ||
47 | return this.authHttp.delete(url) | |
48 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
49 | } | |
50 | } |