source: Sources/frontend/src/app/question.service.ts@ 0e4e3d1

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

Add backend and frontend projects

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import {Injectable} from '@angular/core';
2import {HttpClient} from "@angular/common/http";
3import {Observable} from "rxjs";
4import {QuestionInterface} from "./QuestionInterface";
5import {AnswerInterface} from "./AnswerInterface";
6
7@Injectable({
8 providedIn: 'root'
9})
10export class QuestionService {
11
12 url = "http://localhost:8080/api/questions"
13 answersUrl = "http://localhost:8080/api/answers"
14 studentReactsUrl = "http://localhost:8080/api/student-reacts"
15 professorReactsUrl = "http://localhost:8080/api/professor-reacts"
16
17 constructor(private http: HttpClient) {
18 }
19
20 getAllQuestions(): Observable<QuestionInterface[]> {
21 return this.http.get<QuestionInterface[]>(this.url)
22 }
23
24 getAllQuestionsForCourse(id: number): Observable<QuestionInterface[]> {
25 return this.http.get<QuestionInterface[]>(`${this.url}/${id}`)
26 }
27
28 findQuestionById(id: number): Observable<QuestionInterface> {
29 return this.http.get<QuestionInterface>(`${this.url}/question/${id}`)
30 }
31
32 findAnswersForQuestionWithId(id: number): Observable<AnswerInterface[]> {
33 return this.http.get<AnswerInterface[]>(`${this.answersUrl}/question/${id}`)
34 }
35
36 findLikesForAnswer(id: number) {
37 return this.http.get(`${this.url}/likes/${id}`);
38 }
39
40
41 // @ts-ignore
42 likeAnswer(id: number, username: string, role: string){
43 if (role == 'PROFESSOR') {
44 return this.http.post(`${this.professorReactsUrl}/like/${id}`, username)
45 } else if (role == 'STUDENT') {
46 return this.http.post(`${this.studentReactsUrl}/like/${id}`, username)
47 }
48 }
49
50
51 // @ts-ignore
52 unlikeAnswer(id: number, username: string, role: string) {
53 if (role == 'PROFESSOR') {
54 return this.http.post(`${this.professorReactsUrl}/unlike/${id}`, username)
55 } else if (role == 'STUDENT') {
56 return this.http.post(`${this.studentReactsUrl}/unlike/${id}`, username)
57 }
58 }
59
60}
Note: See TracBrowser for help on using the repository browser.