From 11ac88de40215783835cf6e6259ff0f6cee258dd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 23 Jan 2017 22:16:48 +0100 Subject: Client: add basic support to report video abuses --- client/src/app/shared/video-abuse/index.ts | 2 + .../app/shared/video-abuse/video-abuse.model.ts | 8 ++++ .../app/shared/video-abuse/video-abuse.service.ts | 44 ++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 client/src/app/shared/video-abuse/index.ts create mode 100644 client/src/app/shared/video-abuse/video-abuse.model.ts create mode 100644 client/src/app/shared/video-abuse/video-abuse.service.ts (limited to 'client/src/app/shared/video-abuse') diff --git a/client/src/app/shared/video-abuse/index.ts b/client/src/app/shared/video-abuse/index.ts new file mode 100644 index 000000000..563533ba5 --- /dev/null +++ b/client/src/app/shared/video-abuse/index.ts @@ -0,0 +1,2 @@ +export * from './video-abuse.service'; +export * from './video-abuse.model'; diff --git a/client/src/app/shared/video-abuse/video-abuse.model.ts b/client/src/app/shared/video-abuse/video-abuse.model.ts new file mode 100644 index 000000000..bb0373027 --- /dev/null +++ b/client/src/app/shared/video-abuse/video-abuse.model.ts @@ -0,0 +1,8 @@ +export interface VideoAbuse { + id: string; + reason: string; + reporterPodHost: string; + reporterUsername: string; + videoId: string; + createdAt: Date; +} diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts new file mode 100644 index 000000000..2750a41c7 --- /dev/null +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts @@ -0,0 +1,44 @@ +import { Injectable } from '@angular/core'; +import { Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/map'; + +import { AuthService } from '../core'; +import { AuthHttp } from '../auth'; +import { RestExtractor, ResultList } from '../rest'; +import { VideoAbuse } from './video-abuse.model'; + +@Injectable() +export class VideoAbuseService { + private static BASE_VIDEO_ABUSE_URL = '/api/v1/videos/'; + + constructor( + private authHttp: AuthHttp, + private restExtractor: RestExtractor + ) {} + + getVideoAbuses() { + return this.authHttp.get(VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse') + .map(this.restExtractor.extractDataList) + .map(this.extractVideoAbuses) + } + + reportVideo(id: string, reason: string) { + const body = { + reason + }; + const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'; + + return this.authHttp.post(url, body) + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)); + } + + private extractVideoAbuses(result: ResultList) { + const videoAbuses: VideoAbuse[] = result.data; + const totalVideoAbuses = result.total; + + return { videoAbuses, totalVideoAbuses }; + } +} -- cgit v1.2.3