From 37a44fc915eef2140e22ceb96aba6b6eb2509007 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 17 Jun 2021 16:02:38 +0200 Subject: Add ability to search playlists --- .../src/app/shared/shared-search/search.service.ts | 44 ++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'client/src/app/shared/shared-search') diff --git a/client/src/app/shared/shared-search/search.service.ts b/client/src/app/shared/shared-search/search.service.ts index 15c4a7012..ad258f5e5 100644 --- a/client/src/app/shared/shared-search/search.service.ts +++ b/client/src/app/shared/shared-search/search.service.ts @@ -3,10 +3,17 @@ import { catchError, map, switchMap } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core' -import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' -import { ResultList, SearchTargetType, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '@shared/models' +import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' +import { + ResultList, + SearchTargetType, + Video as VideoServerModel, + VideoChannel as VideoChannelServerModel, + VideoPlaylist as VideoPlaylistServerModel +} from '@shared/models' import { environment } from '../../../environments/environment' +import { VideoPlaylist, VideoPlaylistService } from '../shared-video-playlist' import { AdvancedSearch } from './advanced-search.model' @Injectable() @@ -17,7 +24,8 @@ export class SearchService { private authHttp: HttpClient, private restExtractor: RestExtractor, private restService: RestService, - private videoService: VideoService + private videoService: VideoService, + private playlistService: VideoPlaylistService ) { // Add ability to override search endpoint if the user updated this local storage key const searchUrl = peertubeLocalStorage.getItem('search-url') @@ -85,4 +93,34 @@ export class SearchService { catchError(err => this.restExtractor.handleError(err)) ) } + + searchVideoPlaylists (parameters: { + search: string, + searchTarget?: SearchTargetType, + componentPagination?: ComponentPaginationLight + }): Observable> { + const { search, componentPagination, searchTarget } = parameters + + const url = SearchService.BASE_SEARCH_URL + 'video-playlists' + + let pagination: RestPagination + if (componentPagination) { + pagination = this.restService.componentPaginationToRestPagination(componentPagination) + } + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination) + params = params.append('search', search) + + if (searchTarget) { + params = params.append('searchTarget', searchTarget as string) + } + + return this.authHttp + .get>(url, { params }) + .pipe( + switchMap(res => this.playlistService.extractPlaylists(res)), + catchError(err => this.restExtractor.handleError(err)) + ) + } } -- cgit v1.2.3