[8423429] | 1 | import { Injectable } from '@angular/core';
|
---|
| 2 | import {HttpClient, HttpParams} from "@angular/common/http";
|
---|
| 3 | import {Router} from "@angular/router";
|
---|
| 4 | import {QuestionInterface} from "./QuestionInterface";
|
---|
| 5 | import {QuestionTaggedWithCategoryInterface} from "./question-tagged-with-category-interface";
|
---|
| 6 |
|
---|
| 7 | @Injectable({
|
---|
| 8 | providedIn: 'root'
|
---|
| 9 | })
|
---|
| 10 | export class AddQuestionService {
|
---|
| 11 |
|
---|
| 12 | url = "http://localhost:8080/api/questions/add"
|
---|
| 13 | taggingUrl = "http://localhost:8080/api/tagged-questions/add/"
|
---|
| 14 | constructor(private http: HttpClient, private router: Router) {
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | add(title:string,content:string,studentUserame:string,courseId:number,categories:number[]){
|
---|
| 18 | const params = new HttpParams()
|
---|
| 19 | .append("title",title)
|
---|
| 20 | .append("content",content)
|
---|
| 21 | .append("studentUserame",studentUserame)
|
---|
| 22 | .append("courseId",courseId)
|
---|
| 23 | this.http.get<QuestionInterface>(this.url, {params:params})
|
---|
| 24 | .subscribe(resp => {
|
---|
| 25 | const taggingParams= new HttpParams()
|
---|
| 26 | .append("questionId",resp.id)
|
---|
| 27 | for(let category of categories){
|
---|
| 28 | this.http.get<QuestionTaggedWithCategoryInterface>(this.taggingUrl+category,{params:taggingParams})
|
---|
| 29 | .subscribe(resp => {
|
---|
| 30 | console.log(resp)
|
---|
| 31 | })
|
---|
| 32 | }
|
---|
| 33 | this.router.navigate(['/details/'+courseId]);
|
---|
| 34 | })
|
---|
| 35 | }
|
---|
| 36 | }
|
---|