X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fsearch%2Fsearch.service.ts;h=cd3bdad356443812c0e5429192c16bc80d39d58a;hb=f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9;hp=c6106afd659f2c57fc7295eb8c7b8bd449b1d755;hpb=0b18f4aa80df8868bf34605423c7a298dffbb2aa;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts index c6106afd6..cd3bdad35 100644 --- a/client/src/app/search/search.service.ts +++ b/client/src/app/search/search.service.ts @@ -1,4 +1,4 @@ -import { catchError, switchMap } from 'rxjs/operators' +import { catchError, map, switchMap } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { Observable } from 'rxjs' @@ -6,13 +6,11 @@ import { ComponentPagination } from '@app/shared/rest/component-pagination.model import { VideoService } from '@app/shared/video/video.service' 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 { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared' +import { Video } from '@app/shared/video/video.model' import { AdvancedSearch } from '@app/search/advanced-search.model' - -export type SearchResult = { - videosResult: { totalVideos: number, videos: Video[] } -} +import { VideoChannel } from '@app/shared/video-channel/video-channel.model' +import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' @Injectable() export class SearchService { @@ -36,20 +34,11 @@ export class SearchService { let params = new HttpParams() 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 (search) params = params.append('search', search) - if (Array.isArray(value)) { - for (const v of value) params = params.append(name, v) - } else { - params = params.append(name, value) - } - } + const advancedSearchObject = advancedSearch.toAPIObject() + params = this.restService.addObjectParams(params, advancedSearchObject) return this.authHttp .get>(url, { params }) @@ -58,4 +47,24 @@ export class SearchService { catchError(err => this.restExtractor.handleError(err)) ) } + + searchVideoChannels ( + search: string, + componentPagination: ComponentPagination + ): Observable<{ data: VideoChannel[], total: number }> { + const url = SearchService.BASE_SEARCH_URL + 'video-channels' + + const pagination = this.restService.componentPaginationToRestPagination(componentPagination) + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination) + params = params.append('search', search) + + return this.authHttp + .get>(url, { params }) + .pipe( + map(res => VideoChannelService.extractVideoChannels(res)), + catchError(err => this.restExtractor.handleError(err)) + ) + } }