1 import { Injectable } from '@angular/core'
2 import 'rxjs/add/operator/catch'
3 import 'rxjs/add/operator/map'
4 import { Observable } from 'rxjs/Observable'
5 import { RestExtractor } from '../rest/rest-extractor.service'
6 import { RestService } from '../rest/rest.service'
7 import { HttpClient } from '@angular/common/http'
8 import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos'
9 import { AccountService } from '../account/account.service'
10 import { ResultList } from '../../../../../shared'
11 import { VideoChannel } from './video-channel.model'
14 export class VideoChannelService {
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor,
18 private restService: RestService
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))
27 private extractVideoChannels (result: ResultList<VideoChannelServer>) {
28 const videoChannels: VideoChannel[] = []
30 for (const videoChannelJSON of result.data) {
31 videoChannels.push(new VideoChannel(videoChannelJSON))
34 return { data: videoChannels, total: result.total }