From d3e91a5f72ac9c986cdb67d7d6c85bb4819e680c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Apr 2018 15:43:19 +0200 Subject: Add video channel account list --- .../shared/video-channel/video-channel.service.ts | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 client/src/app/shared/video-channel/video-channel.service.ts (limited to 'client/src/app/shared/video-channel/video-channel.service.ts') diff --git a/client/src/app/shared/video-channel/video-channel.service.ts b/client/src/app/shared/video-channel/video-channel.service.ts new file mode 100644 index 000000000..1f9088c38 --- /dev/null +++ b/client/src/app/shared/video-channel/video-channel.service.ts @@ -0,0 +1,36 @@ +import { Injectable } from '@angular/core' +import 'rxjs/add/operator/catch' +import 'rxjs/add/operator/map' +import { Observable } from 'rxjs/Observable' +import { RestExtractor } from '../rest/rest-extractor.service' +import { RestService } from '../rest/rest.service' +import { HttpClient } from '@angular/common/http' +import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' +import { AccountService } from '../account/account.service' +import { ResultList } from '../../../../../shared' +import { VideoChannel } from './video-channel.model' + +@Injectable() +export class VideoChannelService { + constructor ( + private authHttp: HttpClient, + private restExtractor: RestExtractor, + private restService: RestService + ) {} + + getVideoChannels (accountId: number): Observable> { + return this.authHttp.get>(AccountService.BASE_ACCOUNT_URL + accountId + '/video-channels') + .map(res => this.extractVideoChannels(res)) + .catch((res) => this.restExtractor.handleError(res)) + } + + private extractVideoChannels (result: ResultList) { + const videoChannels: VideoChannel[] = [] + + for (const videoChannelJSON of result.data) { + videoChannels.push(new VideoChannel(videoChannelJSON)) + } + + return { data: videoChannels, total: result.total } + } +} -- cgit v1.2.3