source: Sources/frontend/src/app/add-question.service.ts@ 8423429

Last change on this file since 8423429 was 8423429, checked in by AngelNasev <angel.nasev@…>, 15 months ago

Add backend and frontend projects

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import { Injectable } from '@angular/core';
2import {HttpClient, HttpParams} from "@angular/common/http";
3import {Router} from "@angular/router";
4import {QuestionInterface} from "./QuestionInterface";
5import {QuestionTaggedWithCategoryInterface} from "./question-tagged-with-category-interface";
6
7@Injectable({
8 providedIn: 'root'
9})
10export 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}
Note: See TracBrowser for help on using the repository browser.