diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-23 17:58:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (patch) | |
tree | 2050443febcdb2a3eec68b7bbf9687e26dcb24dc /client/src/app/search/search.service.ts | |
parent | 240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e (diff) | |
download | PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.gz PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.zst PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.zip |
Add ability to search video channels
Diffstat (limited to 'client/src/app/search/search.service.ts')
-rw-r--r-- | client/src/app/search/search.service.ts | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts index a37c49161..cd3bdad35 100644 --- a/client/src/app/search/search.service.ts +++ b/client/src/app/search/search.service.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { catchError, switchMap } from 'rxjs/operators' | 1 | import { catchError, map, switchMap } from 'rxjs/operators' |
2 | import { HttpClient, HttpParams } from '@angular/common/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { Observable } from 'rxjs' | 4 | import { Observable } from 'rxjs' |
@@ -6,13 +6,11 @@ import { ComponentPagination } from '@app/shared/rest/component-pagination.model | |||
6 | import { VideoService } from '@app/shared/video/video.service' | 6 | import { VideoService } from '@app/shared/video/video.service' |
7 | import { RestExtractor, RestService } from '@app/shared' | 7 | import { RestExtractor, RestService } from '@app/shared' |
8 | import { environment } from 'environments/environment' | 8 | import { environment } from 'environments/environment' |
9 | import { ResultList, Video } from '../../../../shared' | 9 | import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared' |
10 | import { Video as VideoServerModel } from '@app/shared/video/video.model' | 10 | import { Video } from '@app/shared/video/video.model' |
11 | import { AdvancedSearch } from '@app/search/advanced-search.model' | 11 | import { AdvancedSearch } from '@app/search/advanced-search.model' |
12 | 12 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
13 | export type SearchResult = { | 13 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
14 | videosResult: { totalVideos: number, videos: Video[] } | ||
15 | } | ||
16 | 14 | ||
17 | @Injectable() | 15 | @Injectable() |
18 | export class SearchService { | 16 | export class SearchService { |
@@ -40,17 +38,7 @@ export class SearchService { | |||
40 | if (search) params = params.append('search', search) | 38 | if (search) params = params.append('search', search) |
41 | 39 | ||
42 | const advancedSearchObject = advancedSearch.toAPIObject() | 40 | const advancedSearchObject = advancedSearch.toAPIObject() |
43 | 41 | params = this.restService.addObjectParams(params, advancedSearchObject) | |
44 | for (const name of Object.keys(advancedSearchObject)) { | ||
45 | const value = advancedSearchObject[name] | ||
46 | if (!value) continue | ||
47 | |||
48 | if (Array.isArray(value) && value.length !== 0) { | ||
49 | for (const v of value) params = params.append(name, v) | ||
50 | } else { | ||
51 | params = params.append(name, value) | ||
52 | } | ||
53 | } | ||
54 | 42 | ||
55 | return this.authHttp | 43 | return this.authHttp |
56 | .get<ResultList<VideoServerModel>>(url, { params }) | 44 | .get<ResultList<VideoServerModel>>(url, { params }) |
@@ -59,4 +47,24 @@ export class SearchService { | |||
59 | catchError(err => this.restExtractor.handleError(err)) | 47 | catchError(err => this.restExtractor.handleError(err)) |
60 | ) | 48 | ) |
61 | } | 49 | } |
50 | |||
51 | searchVideoChannels ( | ||
52 | search: string, | ||
53 | componentPagination: ComponentPagination | ||
54 | ): Observable<{ data: VideoChannel[], total: number }> { | ||
55 | const url = SearchService.BASE_SEARCH_URL + 'video-channels' | ||
56 | |||
57 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
58 | |||
59 | let params = new HttpParams() | ||
60 | params = this.restService.addRestGetParams(params, pagination) | ||
61 | params = params.append('search', search) | ||
62 | |||
63 | return this.authHttp | ||
64 | .get<ResultList<VideoChannelServerModel>>(url, { params }) | ||
65 | .pipe( | ||
66 | map(res => VideoChannelService.extractVideoChannels(res)), | ||
67 | catchError(err => this.restExtractor.handleError(err)) | ||
68 | ) | ||
69 | } | ||
62 | } | 70 | } |