aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/search.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/search/search.service.ts')
-rw-r--r--client/src/app/search/search.service.ts44
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 @@
1import { catchError, switchMap } from 'rxjs/operators' 1import { catchError, map, switchMap } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http' 2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { Observable } from 'rxjs' 4import { Observable } from 'rxjs'
@@ -6,13 +6,11 @@ import { ComponentPagination } from '@app/shared/rest/component-pagination.model
6import { VideoService } from '@app/shared/video/video.service' 6import { VideoService } from '@app/shared/video/video.service'
7import { RestExtractor, RestService } from '@app/shared' 7import { RestExtractor, RestService } from '@app/shared'
8import { environment } from 'environments/environment' 8import { environment } from 'environments/environment'
9import { ResultList, Video } from '../../../../shared' 9import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared'
10import { Video as VideoServerModel } from '@app/shared/video/video.model' 10import { Video } from '@app/shared/video/video.model'
11import { AdvancedSearch } from '@app/search/advanced-search.model' 11import { AdvancedSearch } from '@app/search/advanced-search.model'
12 12import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
13export type SearchResult = { 13import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
14 videosResult: { totalVideos: number, videos: Video[] }
15}
16 14
17@Injectable() 15@Injectable()
18export class SearchService { 16export 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}