/* eslint-disable */ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http'; 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'; @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'; 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> { return this.http.post(SERVER_API_URL + 'download/' + projectID, { observe: 'response', responseType: 'blob', }); } getKeywordsAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> { const options: HttpParams = new HttpParams(); options.append('keyWordPrefix', prefix); return this.http.get<Array<AutoCompletionEntry>>(this.resourceKeywordsAutoCompleteDetails, { params: new HttpParams().set('keyWordPrefix', prefix), }); } getProgrammingLanguageAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> { const options: HttpParams = new HttpParams(); options.append('keyWordPrefix', prefix); return this.http.get<Array<AutoCompletionEntry>>(this.resourceProgrammingLanguageAutoCompleteDetails, { params: new HttpParams().set('programmingLanguagePrefix', prefix), }); } getContributorAutoComplete(prefix: string): Observable<Array<AutoCompletionEntry>> { const options: HttpParams = new HttpParams(); options.append('keyWordPrefix', prefix); 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), }); } } export class AutoCompletionEntry { public target: String; public hitCount: Number; constructor() { this.target = ''; this.hitCount = 0; } }