This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
search-service.ts 2.1 KiB
Newer Older
Michael Breu's avatar
Michael Breu committed
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse, HttpParams } from '@angular/common/http';
Michael Breu's avatar
Michael Breu committed
import { Observable } from 'rxjs';

import { SERVER_API_URL } from 'app/app.constants';
import { SearchResultsDTO } from 'app/shared/model/search/search-results-dto.model';
import { SearchInput } from 'app/shared/model/search/search-input.model';
type EntityResponseTypeAutoComplete = HttpResponse<Array<string>>;

Michael Breu's avatar
Michael Breu committed
@Injectable({ providedIn: 'root' })
export class SearchService {
  public resourceSearchUrlPageDetails = SERVER_API_URL + 'api/search/page-details';
  public resourceKeywordsAutoCompleteDetails = SERVER_API_URL + 'api/search/keywordsAutoComplete';
  public resourceProgrammingLanguageAutoCompleteDetails = SERVER_API_URL + 'api/search/programmingLanguageAutoComplete';
  public resourceContributorAutoCompleteDetails = SERVER_API_URL + 'api/search/contributorAutoComplete';

Michael Breu's avatar
Michael Breu committed
  constructor(protected http: HttpClient) {}

  searchPageDetails(searchInput: SearchInput): Observable<SearchResultsDTO> {
    return this.http.post<SearchResultsDTO>(this.resourceSearchUrlPageDetails, searchInput);
  }
  getKeywordsAutoComplete(prefix: string): Observable<Array<string>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
    return this.http.get<Array<string>>(this.resourceKeywordsAutoCompleteDetails, {
      params: new HttpParams().set('keyWordPrefix', prefix),
    });
  }

  getProgrammingLanguageAutoComplete(prefix: string): Observable<Array<string>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
    return this.http.get<Array<string>>(this.resourceProgrammingLanguageAutoCompleteDetails, {
Daniel Rainer's avatar
Daniel Rainer committed
      params: new HttpParams().set('programmingLanguagePrefix', prefix),
  getContributorAutoComplete(prefix: string): Observable<Array<string>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
    return this.http.get<Array<string>>(this.resourceContributorAutoCompleteDetails, {
      params: new HttpParams().set('contributorPrefix', prefix),
    });