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

Skip to content
Snippets Groups Projects
search-service.ts 4.17 KiB
Newer Older
/* eslint-disable */
Michael Breu's avatar
Michael Breu committed
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpResponse } 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';
import { Statistics } from 'app/shared/model/statistics.model';
Michael Breu's avatar
Michael Breu committed

@Injectable({ providedIn: 'root' })
export class SearchService {
  public resourceSearchUrlPageDetails = SERVER_API_URL + 'api/search/page-details';
  public resourceSearchUrlStatisticsForExercise = SERVER_API_URL + 'api/statistics/exercise/';
  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);
  }
  getStatisticsForExercise(exerciseID: string): Observable<Statistics> {
    return this.http.get<Statistics>(this.resourceSearchUrlStatisticsForExercise + exerciseID);
  }

  /**
   * Used to export an exercise as a compressed zip file
   * The file will contain all the three repositories as well as the exercise text and further metadata
   * @param exerciseId
   */
  exportExercise(exerciseId: number): Observable<HttpResponse<Blob>> {
    return this.http.post(SERVER_API_URL + `/api/programming-exercises/${exerciseId}/export-programming-exercise`, '', {
      observe: 'response',
      responseType: 'blob',
    });
  }

  downloadFile(projectID: string): Observable<Object> {
Michael Breu's avatar
Michael Breu committed
    return this.http.post(SERVER_API_URL + 'download/' + projectID, {
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;
  }
}