diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-19 16:17:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-24 14:04:05 +0200 |
commit | 57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (patch) | |
tree | 87ebcd623c06445b9b25a237addefc98a2d64afa /client/src/app/search/search.service.ts | |
parent | 7279b455811f4806dcb74a08d17b837bc22533c1 (diff) | |
download | PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.gz PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.zst PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.zip |
Begin advanced search
Diffstat (limited to 'client/src/app/search/search.service.ts')
-rw-r--r-- | client/src/app/search/search.service.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts new file mode 100644 index 000000000..02d5f5915 --- /dev/null +++ b/client/src/app/search/search.service.ts | |||
@@ -0,0 +1,46 @@ | |||
1 | import { catchError, switchMap } from 'rxjs/operators' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { Observable } from 'rxjs' | ||
5 | import { ComponentPagination } 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 } from '../../../../shared' | ||
10 | import { Video as VideoServerModel } from '@app/shared/video/video.model' | ||
11 | |||
12 | export type SearchResult = { | ||
13 | videosResult: { totalVideos: number, videos: Video[] } | ||
14 | } | ||
15 | |||
16 | @Injectable() | ||
17 | export class SearchService { | ||
18 | static BASE_SEARCH_URL = environment.apiUrl + '/api/v1/search/' | ||
19 | |||
20 | constructor ( | ||
21 | private authHttp: HttpClient, | ||
22 | private restExtractor: RestExtractor, | ||
23 | private restService: RestService, | ||
24 | private videoService: VideoService | ||
25 | ) {} | ||
26 | |||
27 | searchVideos ( | ||
28 | search: string, | ||
29 | componentPagination: ComponentPagination | ||
30 | ): Observable<{ videos: Video[], totalVideos: number }> { | ||
31 | const url = SearchService.BASE_SEARCH_URL + 'videos' | ||
32 | |||
33 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
34 | |||
35 | let params = new HttpParams() | ||
36 | params = this.restService.addRestGetParams(params, pagination) | ||
37 | params = params.append('search', search) | ||
38 | |||
39 | return this.authHttp | ||
40 | .get<ResultList<VideoServerModel>>(url, { params }) | ||
41 | .pipe( | ||
42 | switchMap(res => this.videoService.extractVideos(res)), | ||
43 | catchError(err => this.restExtractor.handleError(err)) | ||
44 | ) | ||
45 | } | ||
46 | } | ||