[8423429] | 1 | import {Injectable} from '@angular/core';
|
---|
| 2 | import {HttpClient} from "@angular/common/http";
|
---|
| 3 | import {Observable} from "rxjs";
|
---|
| 4 | import {QuestionInterface} from "./QuestionInterface";
|
---|
| 5 | import {AnswerInterface} from "./AnswerInterface";
|
---|
| 6 |
|
---|
| 7 | @Injectable({
|
---|
| 8 | providedIn: 'root'
|
---|
| 9 | })
|
---|
| 10 | export 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 | }
|
---|