import { Injectable } from '@angular/core';
-import { Http } from '@angular/http';
+import { Http, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
videoCategories: Array<{ id: number, label: string }> = [];
videoLicences: Array<{ id: number, label: string }> = [];
+ videoLanguages: Array<{ id: number, label: string }> = [];
constructor(
private authService: AuthService,
});
}
+ loadVideoLanguages() {
+ return this.http.get(VideoService.BASE_VIDEO_URL + 'languages')
+ .map(this.restExtractor.extractDataGet)
+ .subscribe(data => {
+ Object.keys(data).forEach(languageKey => {
+ this.videoLanguages.push({
+ id: parseInt(languageKey),
+ label: data[languageKey]
+ });
+ });
+ });
+ }
+
getVideo(id: string): Observable<Video> {
return this.http.get(VideoService.BASE_VIDEO_URL + id)
.map(this.restExtractor.extractDataGet)
.catch((res) => this.restExtractor.handleError(res));
}
+ updateVideo(video: Video) {
+ const body = {
+ name: video.name,
+ category: video.category,
+ licence: video.licence,
+ language: video.language,
+ description: video.description,
+ tags: video.tags
+ };
+ const headers = new Headers({ 'Content-Type': 'application/json' });
+ const options = new RequestOptions({ headers: headers });
+
+ return this.authHttp.put(`${VideoService.BASE_VIDEO_URL}/${video.id}`, body, options)
+ .map(this.restExtractor.extractDataBool)
+ .catch(this.restExtractor.handleError);
+ }
+
getVideos(pagination: RestPagination, sort: SortField) {
const params = this.restService.buildRestGetParams(pagination, sort);
.catch((res) => this.restExtractor.handleError(res));
}
+ blacklistVideo(id: string) {
+ return this.authHttp.post(VideoService.BASE_VIDEO_URL + id + '/blacklist', {})
+ .map(this.restExtractor.extractDataBool)
+ .catch((res) => this.restExtractor.handleError(res));
+ }
+
private setVideoRate(id: string, rateType: RateType) {
const url = VideoService.BASE_VIDEO_URL + id + '/rate';
const body = {