]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/users/user-history.service.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / users / user-history.service.ts
CommitLineData
e8bffe96 1import { catchError, switchMap } from 'rxjs/operators'
80bfd33c
C
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core'
67ed6552
C
4import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core'
5import { ResultList } from '@shared/models'
6import { environment } from '../../../../environments/environment'
80bfd33c 7import { Video } from '../video/video.model'
67ed6552 8import { VideoService } from '../video/video.service'
80bfd33c
C
9
10@Injectable()
11export 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
c1f7a737 21 list (historyPagination: ComponentPaginationLight, search?: string) {
4beda9e1 22 const pagination = this.restService.componentToRestPagination(historyPagination)
80bfd33c
C
23
24 let params = new HttpParams()
25 params = this.restService.addRestGetParams(params, pagination)
4b4635bd
RK
26
27 if (search) params = params.append('search', search)
80bfd33c
C
28
29 return this.authHttp
30 .get<ResultList<Video>>(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL, { params })
31 .pipe(
32 switchMap(res => this.videoService.extractVideos(res)),
33 catchError(err => this.restExtractor.handleError(err))
34 )
35 }
36
c1f7a737 37 deleteElement (video: Video) {
7177b46c
C
38 return this.authHttp
39 .delete(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL + '/' + video.id)
40 .pipe(catchError(err => this.restExtractor.handleError(err)))
41 }
42
c1f7a737 43 clearAll () {
80bfd33c
C
44 return this.authHttp
45 .post(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL + '/remove', {})
e8bffe96 46 .pipe(catchError(err => this.restExtractor.handleError(err)))
80bfd33c
C
47 }
48}