2018-05-15 04:55:51 -05:00
|
|
|
import { catchError, map } from 'rxjs/operators'
|
2017-09-14 04:57:49 -05:00
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http'
|
2017-12-11 10:36:46 -06:00
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
import { SortMeta } from 'primeng/components/common/sortmeta'
|
2018-05-15 04:55:51 -05:00
|
|
|
import { Observable } from 'rxjs'
|
2018-08-13 04:54:11 -05:00
|
|
|
import { ResultList, VideoAbuse, VideoAbuseUpdate } from '../../../../../shared'
|
2017-12-11 10:36:46 -06:00
|
|
|
import { environment } from '../../../environments/environment'
|
2018-01-31 03:41:44 -06:00
|
|
|
import { RestExtractor, RestPagination, RestService } from '../rest'
|
2017-01-23 15:16:48 -06:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class VideoAbuseService {
|
2017-12-11 10:36:46 -06:00
|
|
|
private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
|
2017-01-23 15:16:48 -06:00
|
|
|
|
2017-06-16 07:32:15 -05:00
|
|
|
constructor (
|
2017-09-14 04:57:49 -05:00
|
|
|
private authHttp: HttpClient,
|
|
|
|
private restService: RestService,
|
2017-01-23 15:16:48 -06:00
|
|
|
private restExtractor: RestExtractor
|
|
|
|
) {}
|
|
|
|
|
2017-09-14 04:57:49 -05:00
|
|
|
getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
|
|
|
|
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
|
|
|
|
|
|
|
|
let params = new HttpParams()
|
|
|
|
params = this.restService.addRestGetParams(params, pagination, sort)
|
|
|
|
|
|
|
|
return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
|
2018-05-15 04:55:51 -05:00
|
|
|
.pipe(
|
|
|
|
map(res => this.restExtractor.convertResultListDateToHuman(res)),
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
2017-01-23 15:16:48 -06:00
|
|
|
}
|
|
|
|
|
2017-07-11 09:01:56 -05:00
|
|
|
reportVideo (id: number, reason: string) {
|
2017-09-14 04:57:49 -05:00
|
|
|
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
|
2017-01-23 15:16:48 -06:00
|
|
|
const body = {
|
|
|
|
reason
|
2017-06-16 07:32:15 -05:00
|
|
|
}
|
2017-01-23 15:16:48 -06:00
|
|
|
|
|
|
|
return this.authHttp.post(url, body)
|
2018-05-15 04:55:51 -05:00
|
|
|
.pipe(
|
|
|
|
map(this.restExtractor.extractDataBool),
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
2017-01-23 15:16:48 -06:00
|
|
|
}
|
2018-08-13 04:54:11 -05:00
|
|
|
|
|
|
|
updateVideoAbuse (videoAbuse: VideoAbuse, abuseUpdate: VideoAbuseUpdate) {
|
|
|
|
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
|
|
|
|
|
|
|
|
return this.authHttp.put(url, abuseUpdate)
|
|
|
|
.pipe(
|
|
|
|
map(this.restExtractor.extractDataBool),
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
removeVideoAbuse (videoAbuse: VideoAbuse) {
|
|
|
|
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
|
|
|
|
|
|
|
|
return this.authHttp.delete(url)
|
|
|
|
.pipe(
|
|
|
|
map(this.restExtractor.extractDataBool),
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
|
|
|
}}
|