@@ -2,14 +2,19 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular
22import { Injectable } from '@angular/core' ;
33import { API_CONFIG } from '../app/api.config' ;
44import { catchError , Observable , throwError } from 'rxjs' ;
5- import { SingleQuestionResponse , QuestionResponse , QuestionBody } from '../app/questions/question.model' ;
5+ import {
6+ SingleQuestionResponse ,
7+ QuestionResponse ,
8+ QuestionBody ,
9+ MessageOnlyResponse ,
10+ } from '../app/questions/question.model' ;
611import { TopicResponse } from '../app/questions/topic.model' ;
712
813@Injectable ( {
914 providedIn : 'root' ,
1015} )
1116export class QuestionService {
12- private baseUrl = API_CONFIG . baseUrl ;
17+ private baseUrl = API_CONFIG . baseUrl + '/questions' ;
1318
1419 private httpOptions = {
1520 headers : new HttpHeaders ( {
@@ -41,11 +46,11 @@ export class QuestionService {
4146 }
4247
4348 // send request
44- return this . http . get < QuestionResponse > ( this . baseUrl + '/questions' , { params } ) ;
49+ return this . http . get < QuestionResponse > ( this . baseUrl , { params } ) ;
4550 }
4651
47- getQuestionByID ( id : number ) : Observable < QuestionResponse > {
48- return this . http . get < QuestionResponse > ( this . baseUrl + '/questions /' + id ) ;
52+ getQuestionByID ( id : number ) : Observable < SingleQuestionResponse > {
53+ return this . http . get < SingleQuestionResponse > ( this . baseUrl + '/' + id ) ;
4954 }
5055
5156 getQuestionByParam ( topics : string [ ] , difficulty : string , limit ?: number ) : Observable < QuestionResponse > {
@@ -56,28 +61,32 @@ export class QuestionService {
5661 }
5762 params = params . append ( 'topics' , topics . join ( ',' ) ) . append ( 'difficulty' , difficulty ) ;
5863
59- return this . http . get < QuestionResponse > ( this . baseUrl + '/questions/ search' , { params } ) ;
64+ return this . http . get < QuestionResponse > ( this . baseUrl + '/search' , { params } ) ;
6065 }
6166
6267 getTopics ( ) : Observable < TopicResponse > {
63- return this . http . get < TopicResponse > ( this . baseUrl + '/questions/ topics' ) ;
68+ return this . http . get < TopicResponse > ( this . baseUrl + '/topics' ) ;
6469 }
6570
6671 addQuestion ( question : QuestionBody ) : Observable < SingleQuestionResponse > {
6772 return this . http
68- . post < SingleQuestionResponse > ( this . baseUrl + '/questions' , question , this . httpOptions )
73+ . post < SingleQuestionResponse > ( this . baseUrl , question , this . httpOptions )
6974 . pipe ( catchError ( this . handleError ) ) ;
7075 }
7176
7277 updateQuestion ( id : number , question : QuestionBody ) : Observable < SingleQuestionResponse > {
7378 return this . http
74- . put < SingleQuestionResponse > ( this . baseUrl + '/questions/ ' + id , question , this . httpOptions )
79+ . put < SingleQuestionResponse > ( this . baseUrl + '/' + id , question , this . httpOptions )
7580 . pipe ( catchError ( this . handleError ) ) ;
7681 }
7782
7883 deleteQuestion ( id : number ) : Observable < SingleQuestionResponse > {
84+ return this . http . delete < SingleQuestionResponse > ( this . baseUrl + '/' + id ) . pipe ( catchError ( this . handleError ) ) ;
85+ }
86+
87+ deleteQuestions ( ids : number [ ] ) : Observable < MessageOnlyResponse > {
7988 return this . http
80- . delete < SingleQuestionResponse > ( this . baseUrl + '/questions/' + id )
89+ . post < MessageOnlyResponse > ( this . baseUrl + '/delete' , { ids } , this . httpOptions )
8190 . pipe ( catchError ( this . handleError ) ) ;
8291 }
8392
0 commit comments