diff --git a/frontend/src/_services/question.service.ts b/frontend/src/_services/question.service.ts index ace226a8c7..eac7679ba7 100644 --- a/frontend/src/_services/question.service.ts +++ b/frontend/src/_services/question.service.ts @@ -2,19 +2,14 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular import { Injectable } from '@angular/core'; import { API_CONFIG } from '../app/api.config'; import { catchError, Observable, throwError } from 'rxjs'; -import { - SingleQuestionResponse, - QuestionResponse, - QuestionBody, - MessageOnlyResponse, -} from '../app/questions/question.model'; +import { SingleQuestionResponse, QuestionResponse, QuestionBody } from '../app/questions/question.model'; import { TopicResponse } from '../app/questions/topic.model'; @Injectable({ providedIn: 'root', }) export class QuestionService { - private baseUrl = API_CONFIG.baseUrl + '/questions'; + private baseUrl = API_CONFIG.baseUrl; private httpOptions = { headers: new HttpHeaders({ @@ -46,11 +41,11 @@ export class QuestionService { } // send request - return this.http.get(this.baseUrl, { params }); + return this.http.get(this.baseUrl + '/questions', { params }); } - getQuestionByID(id: number): Observable { - return this.http.get(this.baseUrl + '/' + id); + getQuestionByID(id: number): Observable { + return this.http.get(this.baseUrl + '/questions/' + id); } getQuestionByParam(topics: string[], difficulty: string, limit?: number): Observable { @@ -61,32 +56,28 @@ export class QuestionService { } params = params.append('topics', topics.join(',')).append('difficulty', difficulty); - return this.http.get(this.baseUrl + '/search', { params }); + return this.http.get(this.baseUrl + '/questions/search', { params }); } getTopics(): Observable { - return this.http.get(this.baseUrl + '/topics'); + return this.http.get(this.baseUrl + '/questions/topics'); } addQuestion(question: QuestionBody): Observable { return this.http - .post(this.baseUrl, question, this.httpOptions) + .post(this.baseUrl + '/questions', question, this.httpOptions) .pipe(catchError(this.handleError)); } updateQuestion(id: number, question: QuestionBody): Observable { return this.http - .put(this.baseUrl + '/' + id, question, this.httpOptions) + .put(this.baseUrl + '/questions/' + id, question, this.httpOptions) .pipe(catchError(this.handleError)); } deleteQuestion(id: number): Observable { - return this.http.delete(this.baseUrl + '/' + id).pipe(catchError(this.handleError)); - } - - deleteQuestions(ids: number[]): Observable { return this.http - .post(this.baseUrl + '/delete', { ids }, this.httpOptions) + .delete(this.baseUrl + '/questions/' + id) .pipe(catchError(this.handleError)); }