]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/search/search.service.ts
Add advanced search in client
[github/Chocobozzz/PeerTube.git] / client / src / app / search / search.service.ts
index 02d5f5915c18032d12ffbdcfffe7df9c0181d942..c6106afd659f2c57fc7295eb8c7b8bd449b1d755 100644 (file)
@@ -8,6 +8,7 @@ import { RestExtractor, RestService } from '@app/shared'
 import { environment } from 'environments/environment'
 import { ResultList, Video } from '../../../../shared'
 import { Video as VideoServerModel } from '@app/shared/video/video.model'
+import { AdvancedSearch } from '@app/search/advanced-search.model'
 
 export type SearchResult = {
   videosResult: { totalVideos: number, videos: Video[] }
@@ -26,7 +27,8 @@ export class SearchService {
 
   searchVideos (
     search: string,
-    componentPagination: ComponentPagination
+    componentPagination: ComponentPagination,
+    advancedSearch: AdvancedSearch
   ): Observable<{ videos: Video[], totalVideos: number }> {
     const url = SearchService.BASE_SEARCH_URL + 'videos'
 
@@ -36,6 +38,19 @@ export class SearchService {
     params = this.restService.addRestGetParams(params, pagination)
     params = params.append('search', search)
 
+    const advancedSearchObject = advancedSearch.toAPIObject()
+
+    for (const name of Object.keys(advancedSearchObject)) {
+      const value = advancedSearchObject[name]
+      if (!value) continue
+
+      if (Array.isArray(value)) {
+        for (const v of value) params = params.append(name, v)
+      } else {
+        params = params.append(name, value)
+      }
+    }
+
     return this.authHttp
                .get<ResultList<VideoServerModel>>(url, { params })
                .pipe(