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

Skip to content
Snippets Groups Projects
exercise.service.ts 1.18 KiB
Newer Older
Michael Breu's avatar
Michael Breu committed
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
Michael Breu's avatar
Michael Breu committed
import { Observable } from 'rxjs';
import { SearchResultDTO } from 'app/shared/model/search/search-result-dto.model';
Michael Breu's avatar
Michael Breu committed

import { SERVER_API_URL } from 'app/app.constants';

@Injectable({ providedIn: 'root' })
export class ExerciseService {
    public resourceUrl = SERVER_API_URL + 'api/exerciseFile/';
    public exerciseUrl = SERVER_API_URL + 'api/exercise/';
Michael Breu's avatar
Michael Breu committed

    constructor(private http: HttpClient) {}

    public loadExerciseFile(exerciseId: string, filePath: string): Observable<string> {
        const headers = new HttpHeaders(); // .set('Content-Type', 'text/plain; charset=utf-8');
Michael Breu's avatar
Michael Breu committed
        const options: HttpParams = new HttpParams();
        options.append('filePath', filePath);

        return this.http.get<string>(this.resourceUrl + exerciseId, {
            headers,
             params: new HttpParams().set('filePath', filePath),
             responseType: 'text' as 'json'
             });
    public loadExercise(exerciseId: string): Observable<SearchResultDTO> {

        return this.http.get<SearchResultDTO>(this.exerciseUrl + exerciseId);
    }
Michael Breu's avatar
Michael Breu committed
}