From d38b82810638b9f664c9016fac2684454c273a77 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Mar 2017 21:35:43 +0100 Subject: Add like/dislike system for videos --- client/src/app/videos/shared/video.service.ts | 43 ++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'client/src/app/videos/shared/video.service.ts') diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index 7094d9a34..8bb5a2933 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts @@ -6,8 +6,16 @@ import 'rxjs/add/operator/map'; import { Search } from '../../shared'; import { SortField } from './sort-field.type'; +import { RateType } from './rate-type.type'; import { AuthService } from '../../core'; -import { AuthHttp, RestExtractor, RestPagination, RestService, ResultList } from '../../shared'; +import { + AuthHttp, + RestExtractor, + RestPagination, + RestService, + ResultList, + UserService +} from '../../shared'; import { Video } from './video.model'; @Injectable() @@ -56,14 +64,41 @@ export class VideoService { } reportVideo(id: string, reason: string) { + const url = VideoService.BASE_VIDEO_URL + id + '/abuse'; const body = { reason }; - const url = VideoService.BASE_VIDEO_URL + id + '/abuse'; return this.authHttp.post(url, body) - .map(this.restExtractor.extractDataBool) - .catch((res) => this.restExtractor.handleError(res)); + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)); + } + + setVideoLike(id: string) { + return this.setVideoRate(id, 'like'); + } + + setVideoDislike(id: string) { + return this.setVideoRate(id, 'dislike'); + } + + getUserVideoRating(id: string) { + const url = UserService.BASE_USERS_URL + '/me/videos/' + id + '/rating'; + + return this.authHttp.get(url) + .map(this.restExtractor.extractDataGet) + .catch((res) => this.restExtractor.handleError(res)); + } + + private setVideoRate(id: string, rateType: RateType) { + const url = VideoService.BASE_VIDEO_URL + id + '/rate'; + const body = { + rating: rateType + }; + + return this.authHttp.put(url, body) + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)); } private extractVideos(result: ResultList) { -- cgit v1.2.3