1 import { catchError, map, switchMap } from 'rxjs/operators'
2 import { HttpClient, HttpParams } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core'
5 import { ResultList } from '@shared/models'
6 import { environment } from '../../../../environments/environment'
7 import { Video } from '../video/video.model'
8 import { VideoService } from '../video/video.service'
11 export class UserHistoryService {
12 static BASE_USER_VIDEOS_HISTORY_URL = environment.apiUrl + '/api/v1/users/me/history/videos'
15 private authHttp: HttpClient,
16 private restExtractor: RestExtractor,
17 private restService: RestService,
18 private videoService: VideoService
21 getUserVideosHistory (historyPagination: ComponentPaginationLight, search?: string) {
22 const pagination = this.restService.componentPaginationToRestPagination(historyPagination)
24 let params = new HttpParams()
25 params = this.restService.addRestGetParams(params, pagination)
27 if (search) params = params.append('search', search)
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))