diff options
Diffstat (limited to 'client/src/app/search/search.service.ts')
-rw-r--r-- | client/src/app/search/search.service.ts | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts index 3cad5aaa7..fdb12ea2c 100644 --- a/client/src/app/search/search.service.ts +++ b/client/src/app/search/search.service.ts | |||
@@ -1,17 +1,18 @@ | |||
1 | import { Observable } from 'rxjs' | ||
1 | import { catchError, map, switchMap } from 'rxjs/operators' | 2 | import { catchError, map, switchMap } from 'rxjs/operators' |
2 | import { HttpClient, HttpParams } from '@angular/common/http' | 3 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
4 | import { Observable } from 'rxjs' | ||
5 | import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model' | ||
6 | import { VideoService } from '@app/shared/video/video.service' | ||
7 | import { RestExtractor, RestService } from '@app/shared' | ||
8 | import { environment } from '../../environments/environment' | ||
9 | import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared' | ||
10 | import { Video } from '@app/shared/video/video.model' | ||
11 | import { AdvancedSearch } from '@app/search/advanced-search.model' | 5 | import { AdvancedSearch } from '@app/search/advanced-search.model' |
6 | import { RestExtractor, RestPagination, RestService } from '@app/shared' | ||
7 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' | ||
8 | import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model' | ||
12 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | 9 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' |
13 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | 10 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
14 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' | 11 | import { Video } from '@app/shared/video/video.model' |
12 | import { VideoService } from '@app/shared/video/video.service' | ||
13 | import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared' | ||
14 | import { environment } from '../../environments/environment' | ||
15 | import { SearchTargetType } from '@shared/models/search/search-target-query.model' | ||
15 | 16 | ||
16 | @Injectable() | 17 | @Injectable() |
17 | export class SearchService { | 18 | export class SearchService { |
@@ -30,21 +31,27 @@ export class SearchService { | |||
30 | 31 | ||
31 | searchVideos (parameters: { | 32 | searchVideos (parameters: { |
32 | search: string, | 33 | search: string, |
33 | componentPagination: ComponentPaginationLight, | 34 | componentPagination?: ComponentPaginationLight, |
34 | advancedSearch: AdvancedSearch | 35 | advancedSearch?: AdvancedSearch |
35 | }): Observable<ResultList<Video>> { | 36 | }): Observable<ResultList<Video>> { |
36 | const { search, componentPagination, advancedSearch } = parameters | 37 | const { search, componentPagination, advancedSearch } = parameters |
37 | 38 | ||
38 | const url = SearchService.BASE_SEARCH_URL + 'videos' | 39 | const url = SearchService.BASE_SEARCH_URL + 'videos' |
39 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | 40 | let pagination: RestPagination |
41 | |||
42 | if (componentPagination) { | ||
43 | pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
44 | } | ||
40 | 45 | ||
41 | let params = new HttpParams() | 46 | let params = new HttpParams() |
42 | params = this.restService.addRestGetParams(params, pagination) | 47 | params = this.restService.addRestGetParams(params, pagination) |
43 | 48 | ||
44 | if (search) params = params.append('search', search) | 49 | if (search) params = params.append('search', search) |
45 | 50 | ||
46 | const advancedSearchObject = advancedSearch.toAPIObject() | 51 | if (advancedSearch) { |
47 | params = this.restService.addObjectParams(params, advancedSearchObject) | 52 | const advancedSearchObject = advancedSearch.toAPIObject() |
53 | params = this.restService.addObjectParams(params, advancedSearchObject) | ||
54 | } | ||
48 | 55 | ||
49 | return this.authHttp | 56 | return this.authHttp |
50 | .get<ResultList<VideoServerModel>>(url, { params }) | 57 | .get<ResultList<VideoServerModel>>(url, { params }) |
@@ -56,17 +63,26 @@ export class SearchService { | |||
56 | 63 | ||
57 | searchVideoChannels (parameters: { | 64 | searchVideoChannels (parameters: { |
58 | search: string, | 65 | search: string, |
59 | componentPagination: ComponentPaginationLight | 66 | searchTarget?: SearchTargetType, |
67 | componentPagination?: ComponentPaginationLight | ||
60 | }): Observable<ResultList<VideoChannel>> { | 68 | }): Observable<ResultList<VideoChannel>> { |
61 | const { search, componentPagination } = parameters | 69 | const { search, componentPagination, searchTarget } = parameters |
62 | 70 | ||
63 | const url = SearchService.BASE_SEARCH_URL + 'video-channels' | 71 | const url = SearchService.BASE_SEARCH_URL + 'video-channels' |
64 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | 72 | |
73 | let pagination: RestPagination | ||
74 | if (componentPagination) { | ||
75 | pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
76 | } | ||
65 | 77 | ||
66 | let params = new HttpParams() | 78 | let params = new HttpParams() |
67 | params = this.restService.addRestGetParams(params, pagination) | 79 | params = this.restService.addRestGetParams(params, pagination) |
68 | params = params.append('search', search) | 80 | params = params.append('search', search) |
69 | 81 | ||
82 | if (searchTarget) { | ||
83 | params = params.append('searchTarget', searchTarget as string) | ||
84 | } | ||
85 | |||
70 | return this.authHttp | 86 | return this.authHttp |
71 | .get<ResultList<VideoChannelServerModel>>(url, { params }) | 87 | .get<ResultList<VideoChannelServerModel>>(url, { params }) |
72 | .pipe( | 88 | .pipe( |