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

Skip to content
Snippets Groups Projects
search-service.ts 3.17 KiB
Newer Older
Michael Breu's avatar
Michael Breu committed
import { Injectable } from '@angular/core';
Michael Breu's avatar
Michael Breu committed
import { HttpClient, 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';
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';
  public resourceContributorCreatorAutoCompleteDetails = SERVER_API_URL + 'api/search/contributorCreatorAutoComplete';
  public resourceCreatorAutoCompleteDetails = SERVER_API_URL + 'api/search/creatorAutoComplete';
Michael Breu's avatar
Michael Breu committed
  constructor(protected http: HttpClient) {}

  searchPageDetails(searchInput: SearchInput): Observable<SearchResultsDTO> {
    return this.http.post<SearchResultsDTO>(this.resourceSearchUrlPageDetails, searchInput);
  }
Michael Breu's avatar
Michael Breu committed
  getKeywordsAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
Michael Breu's avatar
Michael Breu committed
    return this.http.get<Array<AutoCompletionEntry>>(this.resourceKeywordsAutoCompleteDetails, {
      params: new HttpParams().set('keyWordPrefix', prefix),
    });
Michael Breu's avatar
Michael Breu committed
  getProgrammingLanguageAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
Michael Breu's avatar
Michael Breu committed
    return this.http.get<Array<AutoCompletionEntry>>(this.resourceProgrammingLanguageAutoCompleteDetails, {
Daniel Rainer's avatar
Daniel Rainer committed
      params: new HttpParams().set('programmingLanguagePrefix', prefix),
Michael Breu's avatar
Michael Breu committed
  getContributorAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
Michael Breu's avatar
Michael Breu committed
    return this.http.get<Array<AutoCompletionEntry>>(this.resourceContributorAutoCompleteDetails, {
      params: new HttpParams().set('contributorPrefix', prefix),
    });
  
   getContributorCreatorAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
    return this.http.get<Array<AutoCompletionEntry>>(this.resourceContributorCreatorAutoCompleteDetails, {
      params: new HttpParams().set('contributorPrefix', prefix),
    });
  }

  getCreatorAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> {
    const options: HttpParams = new HttpParams();
    options.append('keyWordPrefix', prefix);
    return this.http.get<Array<AutoCompletionEntry>>(this.resourceCreatorAutoCompleteDetails, {
      params: new HttpParams().set('contributorPrefix', prefix),
    });
  }

Michael Breu's avatar
Michael Breu committed

export class AutoCompletionEntry {
  public target: String;
  public hitCount: Number;
  constructor() {
    this.target = '';
    this.hitCount = 0;
  }
}