diff options
Diffstat (limited to 'client/src/app/+admin/blacklist/shared/blacklist.service.ts')
-rw-r--r-- | client/src/app/+admin/blacklist/shared/blacklist.service.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/client/src/app/+admin/blacklist/shared/blacklist.service.ts b/client/src/app/+admin/blacklist/shared/blacklist.service.ts new file mode 100644 index 000000000..1b090c9c5 --- /dev/null +++ b/client/src/app/+admin/blacklist/shared/blacklist.service.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Observable } from 'rxjs/Observable' | ||
4 | import 'rxjs/add/operator/catch' | ||
5 | import 'rxjs/add/operator/map' | ||
6 | |||
7 | import { SortMeta } from 'primeng/components/common/sortmeta' | ||
8 | |||
9 | import { RestExtractor, RestPagination, RestService } from '../../../shared' | ||
10 | import { Utils } from '../../../shared' | ||
11 | import { BlacklistedVideo, ResultList } from '../../../../../../shared' | ||
12 | |||
13 | @Injectable() | ||
14 | export class BlacklistService { | ||
15 | private static BASE_BLACKLISTS_URL = '/api/v1/blacklist/' | ||
16 | |||
17 | constructor ( | ||
18 | private authHttp: HttpClient, | ||
19 | private restService: RestService, | ||
20 | private restExtractor: RestExtractor | ||
21 | ) {} | ||
22 | |||
23 | getBlacklist (pagination: RestPagination, sort: SortMeta): Observable<ResultList<BlacklistedVideo>> { | ||
24 | let params = new HttpParams() | ||
25 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
26 | |||
27 | return this.authHttp.get<ResultList<BlacklistedVideo>>(BlacklistService.BASE_BLACKLISTS_URL, { params }) | ||
28 | .map(res => this.restExtractor.convertResultListDateToHuman(res)) | ||
29 | .map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this))) | ||
30 | .catch(res => this.restExtractor.handleError(res)) | ||
31 | } | ||
32 | |||
33 | removeVideoFromBlacklist (entry: BlacklistedVideo) { | ||
34 | return this.authHttp.delete(BlacklistService.BASE_BLACKLISTS_URL + entry.id) | ||
35 | .map(this.restExtractor.extractDataBool) | ||
36 | .catch(res => this.restExtractor.handleError(res)) | ||
37 | } | ||
38 | |||
39 | private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) { | ||
40 | return Object.assign(blacklistedVideo, { | ||
41 | createdAt: Utils.dateToHuman(blacklistedVideo.createdAt) | ||
42 | }) | ||
43 | } | ||
44 | } | ||