]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video-channel/video-channel.service.ts
Update video-channel routes (again)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-channel / video-channel.service.ts
CommitLineData
d3e91a5f
C
1import { Injectable } from '@angular/core'
2import 'rxjs/add/operator/catch'
3import 'rxjs/add/operator/map'
4import { Observable } from 'rxjs/Observable'
5import { RestExtractor } from '../rest/rest-extractor.service'
6import { RestService } from '../rest/rest.service'
7import { HttpClient } from '@angular/common/http'
8import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos'
9import { AccountService } from '../account/account.service'
10import { ResultList } from '../../../../../shared'
11import { VideoChannel } from './video-channel.model'
12
13@Injectable()
14export class VideoChannelService {
15 constructor (
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor,
18 private restService: RestService
19 ) {}
20
21 getVideoChannels (accountId: number): Observable<ResultList<VideoChannel>> {
22 return this.authHttp.get<ResultList<VideoChannelServer>>(AccountService.BASE_ACCOUNT_URL + accountId + '/video-channels')
23 .map(res => this.extractVideoChannels(res))
24 .catch((res) => this.restExtractor.handleError(res))
25 }
26
27 private extractVideoChannels (result: ResultList<VideoChannelServer>) {
28 const videoChannels: VideoChannel[] = []
29
30 for (const videoChannelJSON of result.data) {
31 videoChannels.push(new VideoChannel(videoChannelJSON))
32 }
33
34 return { data: videoChannels, total: result.total }
35 }
36}