1 import { HttpClient, HttpParams } from '@angular/common/http'
2 import { Injectable } from '@angular/core'
3 import { environment } from '../../../environments/environment'
4 import { RestExtractor } from '../rest/rest-extractor.service'
5 import { RestService } from '../rest/rest.service'
6 import { Video } from '../video/video.model'
7 import { catchError, map, switchMap } from 'rxjs/operators'
8 import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
9 import { VideoService } from '@app/shared/video/video.service'
10 import { ResultList } from '../../../../../shared'
13 export class UserHistoryService {
14 static BASE_USER_VIDEOS_HISTORY_URL = environment.apiUrl + '/api/v1/users/me/history/videos'
17 private authHttp: HttpClient,
18 private restExtractor: RestExtractor,
19 private restService: RestService,
20 private videoService: VideoService
23 getUserVideosHistory (historyPagination: ComponentPagination) {
24 const pagination = this.restService.componentPaginationToRestPagination(historyPagination)
26 let params = new HttpParams()
27 params = this.restService.addRestGetParams(params, pagination)
30 .get<ResultList<Video>>(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL, { params })
32 switchMap(res => this.videoService.extractVideos(res)),
33 catchError(err => this.restExtractor.handleError(err))
37 deleteUserVideosHistory () {
39 .post(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL + '/remove', {})
41 map(() => this.restExtractor.extractDataBool()),
42 catchError(err => this.restExtractor.handleError(err))