]>
Commit | Line | Data |
---|---|---|
384ba8b7 C |
1 | import { catchError } from 'rxjs' |
2 | import { environment } from 'src/environments/environment' | |
3 | import { HttpClient } from '@angular/common/http' | |
4 | import { Injectable } from '@angular/core' | |
5 | import { RestExtractor } from '@app/core' | |
6 | import { VideoService } from '@app/shared/shared-main' | |
7 | import { VideoStatsOverall, VideoStatsRetention, VideoStatsTimeserie, VideoStatsTimeserieMetric } from '@shared/models/videos' | |
8 | ||
9 | @Injectable({ | |
10 | providedIn: 'root' | |
11 | }) | |
12 | export class VideoStatsService { | |
13 | static BASE_VIDEO_STATS_URL = environment.apiUrl + '/api/v1/videos/' | |
14 | ||
15 | constructor ( | |
16 | private authHttp: HttpClient, | |
17 | private restExtractor: RestExtractor | |
18 | ) { } | |
19 | ||
20 | getOverallStats (videoId: string) { | |
21 | return this.authHttp.get<VideoStatsOverall>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/overall') | |
22 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
23 | } | |
24 | ||
25 | getTimeserieStats (videoId: string, metric: VideoStatsTimeserieMetric) { | |
26 | return this.authHttp.get<VideoStatsTimeserie>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/timeseries/' + metric) | |
27 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
28 | } | |
29 | ||
30 | getRetentionStats (videoId: string) { | |
31 | return this.authHttp.get<VideoStatsRetention>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/retention') | |
32 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
33 | } | |
34 | } |