]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { catchError, map, switchMap } from 'rxjs/operators' |
80bfd33c C |
2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | |
67ed6552 C |
4 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' |
5 | import { ResultList } from '@shared/models' | |
6 | import { environment } from '../../../../environments/environment' | |
80bfd33c | 7 | import { Video } from '../video/video.model' |
67ed6552 | 8 | import { VideoService } from '../video/video.service' |
80bfd33c C |
9 | |
10 | @Injectable() | |
11 | export class UserHistoryService { | |
12 | static BASE_USER_VIDEOS_HISTORY_URL = environment.apiUrl + '/api/v1/users/me/history/videos' | |
13 | ||
14 | constructor ( | |
15 | private authHttp: HttpClient, | |
16 | private restExtractor: RestExtractor, | |
17 | private restService: RestService, | |
18 | private videoService: VideoService | |
19 | ) {} | |
20 | ||
440d39c5 | 21 | getUserVideosHistory (historyPagination: ComponentPaginationLight) { |
80bfd33c C |
22 | const pagination = this.restService.componentPaginationToRestPagination(historyPagination) |
23 | ||
24 | let params = new HttpParams() | |
25 | params = this.restService.addRestGetParams(params, pagination) | |
26 | ||
27 | return this.authHttp | |
28 | .get<ResultList<Video>>(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL, { params }) | |
29 | .pipe( | |
30 | switchMap(res => this.videoService.extractVideos(res)), | |
31 | catchError(err => this.restExtractor.handleError(err)) | |
32 | ) | |
33 | } | |
34 | ||
35 | deleteUserVideosHistory () { | |
36 | return this.authHttp | |
37 | .post(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL + '/remove', {}) | |
38 | .pipe( | |
39 | map(() => this.restExtractor.extractDataBool()), | |
40 | catchError(err => this.restExtractor.handleError(err)) | |
41 | ) | |
42 | } | |
43 | } |