From 9b034f34e131445ff4dff255df54ac18cd7320f5 Mon Sep 17 00:00:00 2001
From: "alec.schmidt" <alec.schmidt@etu.hesge.ch>
Date: Sat, 10 Jun 2023 21:29:20 +0200
Subject: [PATCH] answers in the dashboard and added update question

---
 API/db/app.db                                 | Bin 36864 -> 36864 bytes
 API/src/database/Database.ts                  |   7 ++
 API/src/routes/BaseRoutes.ts                  |   4 +
 frontend/src/app/Types/types.ts               |   6 +-
 frontend/src/app/admin/admin.component.html   |  57 ++++++++++----
 frontend/src/app/admin/admin.component.ts     |  33 +++++++-
 frontend/src/app/app.module.ts                |   6 +-
 .../create-answer/create-answer.component.css |   0
 .../create-answer.component.html              |  22 ++++++
 .../create-answer.component.spec.ts           |  21 +++++
 .../create-answer/create-answer.component.ts  |  42 ++++++++++
 .../create-question.component.html            |   2 +-
 .../create-question.component.ts              |   1 -
 .../update-question.component.css             |   0
 .../update-question.component.html            |  23 ++++++
 .../update-question.component.spec.ts         |  21 +++++
 .../update-question.component.ts              |  51 +++++++++++++
 .../src/app/services/questions.service.ts     |  72 +++++++++++++-----
 18 files changed, 326 insertions(+), 42 deletions(-)
 create mode 100644 frontend/src/app/question-shit/create-answer/create-answer.component.css
 create mode 100644 frontend/src/app/question-shit/create-answer/create-answer.component.html
 create mode 100644 frontend/src/app/question-shit/create-answer/create-answer.component.spec.ts
 create mode 100644 frontend/src/app/question-shit/create-answer/create-answer.component.ts
 create mode 100644 frontend/src/app/question-shit/update-question/update-question.component.css
 create mode 100644 frontend/src/app/question-shit/update-question/update-question.component.html
 create mode 100644 frontend/src/app/question-shit/update-question/update-question.component.spec.ts
 create mode 100644 frontend/src/app/question-shit/update-question/update-question.component.ts

diff --git a/API/db/app.db b/API/db/app.db
index 64c90b46e77bf7c6bb80320c2b8304adf8bf2b65..944924283c3431b77e348d1080c9c905e85877f5 100644
GIT binary patch
delta 446
zcmZozz|^pSX@WFk%0wAw#*~c-%k(*JG4Oxof5v}nvtYs*eiJTcW=Y1xyyEiIA^~0|
zW_iZK($wOT%>2A!K2AnvamLc()S_a3UIqpRM*dd}{IB?H`6q5x6e!}aFKG0aO{6vO
z$Sf|&7vW)H5Lfm{%*n}jKfE$Oy(qCDBa=Us3+$+G4E*2t`}y~7R#a%=&r4^dwTlw@
zIGM#6!H(hCl)$1Oz|4Pvf&V@Kef|sl7x<6x@7%1Yu!7%(TbPj}CpCwgfq{WXl##O}
zwYY?vSAdm4nvugXFFhwQvzUjEpOrzDk<&3JCp9-QFNKGnmz6=Dk;APhG4JqlkOBY?
CIFAVc

delta 263
zcmZozz|^pSX@WGP^F$eEM(2$Q%k(*JGw^@qf5v}%vtYtmenU=XW=YP(yyEiIB3>qD
zdB(!h)Z&uN{JdgLPDW;N#?s={qGEnt1_lO3{u2!RC-^sSR#aHUA0{fQT#{N`;(mB#
zetJ=2K}Ke(83zkPv~pl+YEDk7LTYh|LQbMWa$-SdNn%c_LP{!#>r|SPo>-Kbs$h?#
zj|*(}6$bt*{HHey8XV#`;slw@sm&bCNTg{Tn-W+Q*cb#D82CSK7EHLpKXHN>55F`c
NXHtG%aeihII{;(0QU3q{

diff --git a/API/src/database/Database.ts b/API/src/database/Database.ts
index 5bb06e6..81715af 100644
--- a/API/src/database/Database.ts
+++ b/API/src/database/Database.ts
@@ -234,6 +234,13 @@ class DBHandler {
         asyncdb.all(query)
         .then(ans => res.status(StatusCodes.OK).json(ans))
     }
+
+    async deleteAnswer(req:express.Request, res:express.Response) {
+        const query = "DELETE from answer WHERE id=" + req.params.id;
+
+        asyncdb.all(query)
+        .then(() => res.status(StatusCodes.OK).end())
+    }
 }
 
 export default new DBHandler();
\ No newline at end of file
diff --git a/API/src/routes/BaseRoutes.ts b/API/src/routes/BaseRoutes.ts
index a5cfef4..e4909d9 100644
--- a/API/src/routes/BaseRoutes.ts
+++ b/API/src/routes/BaseRoutes.ts
@@ -195,6 +195,10 @@ router.post(ROUTE+'/answer', (req: express.Request, res: express.Response) => {
     DBHandler.postAnwsers(req, res);
 })
 
+router.delete(ROUTE+'/answer/:id', (req: express.Request, res: express.Response) => {
+    DBHandler.deleteAnswer(req, res);
+})
+
 // CATEGORIES CRUD
 
 router.post(ROUTE+'/category', (req: express.Request, res: express.Response) => {
diff --git a/frontend/src/app/Types/types.ts b/frontend/src/app/Types/types.ts
index fbd63e1..21e0fd0 100644
--- a/frontend/src/app/Types/types.ts
+++ b/frontend/src/app/Types/types.ts
@@ -17,8 +17,10 @@ export type Question = {
 }
 
 export type Answer = {
-    CORRECT: string;
-    WRONG: string[];
+    id: number;
+    text_answer: string;
+    id_question: number;
+    correct: boolean;
 }
 
 export type Category = {
diff --git a/frontend/src/app/admin/admin.component.html b/frontend/src/app/admin/admin.component.html
index 5bbed70..707a973 100644
--- a/frontend/src/app/admin/admin.component.html
+++ b/frontend/src/app/admin/admin.component.html
@@ -17,20 +17,40 @@
     </table>
     
     <button (click)="modalQuestionCreate=true;" class="mt-20 bg-white w-fit border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2">Create Question</button>
-    <table class="table-auto">
-        <thead class="border-b font-medium dark:border-neutral-500">
-            <th class="px-6 py-4">Question</th>
-            <th class="px-6 py-4">Catégorie</th>
-        </thead>
-        <tbody>
-            <tr *ngFor="let question of questions" class="border-b dark:border-neutral-500">
-                <td class="whitespace-nowrap px-6 py-4">{{question.question}}</td>
-                <td class="whitespace-nowrap px-6 py-4">{{question.category}}</td>
-                <td><button class="bg-teal-200 w-fit border-2 border-teal-600 rounded-lg px-2 hover:bg-teal-400 mt-2">UPDATE</button></td>
-                <td><button class="bg-red-400 w-fit border-2 border-red-600 rounded-lg px-2 hover:bg-red-300 mt-2" (click)="deleteQuestion(question)">DELETE</button></td>
-            </tr>
-        </tbody>
-    </table>
+    <div class="grid grid-cols-2 gap-10">
+    
+        <table class="table-auto w-full h-fit text-left">
+            <thead class="border-b font-medium dark:border-neutral-500">
+                <th class="px-6 py-4">Question</th>
+                <th class="px-6 py-4">Catégorie</th>
+            </thead>
+            <tbody>
+                <tr *ngFor="let question of questions" class="border-b dark:border-neutral-500">
+                    <td class="whitespace-nowrap px-6 py-4 max-w-sm break-all">{{question.question}}</td>
+                    <td class="whitespace-nowrap px-6 py-4">{{question.category}}</td>
+                    <td><button class="bg-teal-200 w-fit border-2 border-teal-600 rounded-lg px-2 hover:bg-teal-400 mt-2" (click)="showQuestionUpdateModal(question)">UPDATE</button></td>
+                    <td><button class="bg-red-400 w-fit border-2 border-red-600 rounded-lg px-2 hover:bg-red-300 mt-2" (click)="deleteQuestion(question)">DELETE</button></td>
+                    <td><button class="bg-teal-200 w-fit border-2 border-teal-600 rounded-lg px-2 hover:bg-teal-400 mt-2" (click)="showSelectedAnswers(question.id)">⇉</button></td>
+                </tr>
+            </tbody>
+        </table>
+        <table class="table-auto w-full h-fit text-left">
+            <thead class="border-b font-medium dark:border-neutral-500">
+                <th class="px-6 py-4">Answer</th>
+                <th class="px-6 py-4">Correct</th>
+            </thead>
+            <tbody>
+                <tr *ngFor="let answer of answers" class="border-b dark:border-neutral-500">
+                    <td class="whitespace-nowrap px-6 py-4">{{answer.text_answer}}</td>
+                    <td class="whitespace-nowrap px-6 py-4">{{answer.correct}}</td>
+                    <td><button class="bg-teal-200 w-fit border-2 border-teal-600 rounded-lg px-2 hover:bg-teal-400 mt-2">UPDATE</button></td>
+                    <td><button class="bg-red-400 w-fit border-2 border-red-600 rounded-lg px-2 hover:bg-red-300 mt-2" (click)="deleteAnswer(answer)">DELETE</button></td>
+                </tr>
+            </tbody>
+            <button *ngIf="buttonCreateAnswer" class=" bg-white w-fit border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2" (click)="modalAnswerCreate = true;">Add Answer</button>
+        </table>
+    </div>
+
     
     
     
@@ -45,4 +65,13 @@
     <div *ngIf="modalQuestionCreate">
         <app-create-question (closeModal)="modalQuestionCreate=false;"></app-create-question>
     </div>
+
+    <div *ngIf="modalAnswerCreate">
+        <app-create-answer [questionID]="selectedQuestionID" (closeModal)="modalAnswerCreate=false;"></app-create-answer>
+    </div>
+
+    <div *ngIf="modalQuestionUpdate">
+        <app-update-question [question]="questionToEdit" (closeModal)="modalQuestionUpdate=false;"></app-update-question>
+    </div>
+
 </div>
diff --git a/frontend/src/app/admin/admin.component.ts b/frontend/src/app/admin/admin.component.ts
index a09535b..6638a40 100644
--- a/frontend/src/app/admin/admin.component.ts
+++ b/frontend/src/app/admin/admin.component.ts
@@ -17,11 +17,17 @@ export class AdminComponent implements OnInit {
     public users!: User[];
     public questions!: Question[];
     public answers!: Answer[];
+    selectedQuestionID!: number;
     userToEdit!: User;
+    questionToEdit!: Question;
+
+    buttonCreateAnswer!: boolean;
 
     modalUpdate: boolean = false;
     modalCreate: boolean = false;
     modalQuestionCreate: boolean = false;
+    modalQuestionUpdate: boolean = false;
+    modalAnswerCreate: boolean = false;
 
     constructor(
       private router: Router,
@@ -41,9 +47,23 @@ export class AdminComponent implements OnInit {
 
       this.questionController.questions.subscribe(questionList => {
         this.questions = questionList;
-      })
-
+      });
+      
       this.questionController.fetchQuestions();
+
+      this.questionController.answers.subscribe(answersList => {
+        this.answers = answersList;
+      });
+    }
+
+    showSelectedAnswers(questionID: number): void {
+      this.buttonCreateAnswer = true;
+      this.selectedQuestionID = questionID;
+      this.questionController.fetchAnswers(questionID);
+    }
+
+    addAnswer(answer: Answer): void {
+      this.questionController.addAnswer(answer);
     }
 
     deleteUser(user:User) {
@@ -54,8 +74,17 @@ export class AdminComponent implements OnInit {
       this.questionController.deleteQuestion(question);
     }
 
+    deleteAnswer(answer: Answer) {
+      this.questionController.deleteAnswer(answer);
+    }
+
     showUpdateModal(user: User){
       this.userToEdit = user;
       this.modalUpdate = true;
     }
+
+    showQuestionUpdateModal(question: Question) {
+      this.questionToEdit = question;
+      this.modalQuestionUpdate = true;
+    }
   }
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts
index 7a1b8c1..e1ac6e8 100644
--- a/frontend/src/app/app.module.ts
+++ b/frontend/src/app/app.module.ts
@@ -12,6 +12,8 @@ import { SignupComponent } from './login-shit/signup/signup.component';
 import { CreateUserComponent } from './user-shit/create-user/create-user.component';
 import { UpdateUserComponent } from './user-shit/update-user/update-user.component';
 import { CreateQuestionComponent } from './question-shit/create-question/create-question.component';
+import { CreateAnswerComponent } from './question-shit/create-answer/create-answer.component';
+import { UpdateQuestionComponent } from './question-shit/update-question/update-question.component';
 
 @NgModule({
   declarations: [
@@ -21,7 +23,9 @@ import { CreateQuestionComponent } from './question-shit/create-question/create-
     SignupComponent,
     CreateUserComponent,
     UpdateUserComponent,
-    CreateQuestionComponent
+    CreateQuestionComponent,
+    CreateAnswerComponent,
+    UpdateQuestionComponent
   ],
   imports: [
     BrowserModule,
diff --git a/frontend/src/app/question-shit/create-answer/create-answer.component.css b/frontend/src/app/question-shit/create-answer/create-answer.component.css
new file mode 100644
index 0000000..e69de29
diff --git a/frontend/src/app/question-shit/create-answer/create-answer.component.html b/frontend/src/app/question-shit/create-answer/create-answer.component.html
new file mode 100644
index 0000000..56f591a
--- /dev/null
+++ b/frontend/src/app/question-shit/create-answer/create-answer.component.html
@@ -0,0 +1,22 @@
+<div class="z-10 relative">
+    <div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"></div>
+    <div class="fixed inset-0 z-10 overflow-y-auto">
+        <div class="flex flex-col min-h-full justify-center p-4 text-center items-center sm:p-0">
+            <div class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 ">
+                <h1 class="mt-2 mx-2 font-bold">Create Answer</h1>
+
+                <form [formGroup]="createAnswer" (ngSubmit)="onSubmit()" class="flex flex-col pb-2 mx-2">
+                    <input class="border-b-4 mt-2 w-full" type="text" placeholder="Text" formControlName="answer">
+                    <div class="my-2 border-b-4">
+                        <label class="mt-2 w-fit">Correct</label><input class="ml-6" type="checkbox" formControlName="correct">
+                    </div>
+                    <div class="flex flex-row justify-between">
+                        <button class="border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2" type="submit">Create</button>
+                        <button class="border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2" (click)="closeModal.emit()">Close</button>
+                    </div>
+                </form>
+
+            </div>
+        </div>
+    </div>
+</div>
\ No newline at end of file
diff --git a/frontend/src/app/question-shit/create-answer/create-answer.component.spec.ts b/frontend/src/app/question-shit/create-answer/create-answer.component.spec.ts
new file mode 100644
index 0000000..71b54af
--- /dev/null
+++ b/frontend/src/app/question-shit/create-answer/create-answer.component.spec.ts
@@ -0,0 +1,21 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { CreateAnswerComponent } from './create-answer.component';
+
+describe('CreateAnswerComponent', () => {
+  let component: CreateAnswerComponent;
+  let fixture: ComponentFixture<CreateAnswerComponent>;
+
+  beforeEach(() => {
+    TestBed.configureTestingModule({
+      declarations: [CreateAnswerComponent]
+    });
+    fixture = TestBed.createComponent(CreateAnswerComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});
diff --git a/frontend/src/app/question-shit/create-answer/create-answer.component.ts b/frontend/src/app/question-shit/create-answer/create-answer.component.ts
new file mode 100644
index 0000000..4d146c1
--- /dev/null
+++ b/frontend/src/app/question-shit/create-answer/create-answer.component.ts
@@ -0,0 +1,42 @@
+import { Component, EventEmitter, Input, Output } from '@angular/core';
+import { FormControl, FormGroup, Validators } from '@angular/forms';
+import { Answer } from 'src/app/Types/types';
+import { QuestionsService } from 'src/app/services/questions.service';
+
+@Component({
+  selector: 'app-create-answer',
+  templateUrl: './create-answer.component.html',
+  styleUrls: ['./create-answer.component.css']
+})
+export class CreateAnswerComponent {
+  createAnswer: FormGroup;
+
+  @Input() questionID: number;
+  @Output() closeModal: EventEmitter<string> = new EventEmitter<string>();
+
+  constructor(private questionsController: QuestionsService) { }
+
+  ngOnInit(): void {
+    this.createAnswer = new FormGroup({
+      answer: new FormControl('', Validators.required),
+      correct: new FormControl(false, Validators.required)
+    });
+  }
+
+  onSubmit() {
+    const answer = this.createAnswer.get("answer")!.value;
+    const correct = this.createAnswer.get("correct")!.value;
+
+    const newAnswer: Answer = {
+      id: undefined,
+      text_answer: answer,
+      correct: correct,
+      id_question: this.questionID
+    }
+
+    console.log(newAnswer)
+
+    this.questionsController.addAnswer(newAnswer);
+    this.closeModal.emit();
+  }
+}
diff --git a/frontend/src/app/question-shit/create-question/create-question.component.html b/frontend/src/app/question-shit/create-question/create-question.component.html
index 494fa77..5e1e49e 100644
--- a/frontend/src/app/question-shit/create-question/create-question.component.html
+++ b/frontend/src/app/question-shit/create-question/create-question.component.html
@@ -8,7 +8,7 @@
                 <form [formGroup]="createQuestion" (ngSubmit)="onSubmit()" class="flex flex-col pb-2 mx-2">
                     <input class="border-b-4 mt-2 w-full" type="text" placeholder="Text" formControlName="question">
                     <select #select id="category" class="form-control" (change)="onSelected(select.value)">
-                        <option default value="">Thème</option>
+                        <option default value="">Theme</option>
                         <option *ngFor="let c of categories" [value]="c.title">{{c.title}}</option>
                     </select>
                     <div class="flex flex-row justify-between">
diff --git a/frontend/src/app/question-shit/create-question/create-question.component.ts b/frontend/src/app/question-shit/create-question/create-question.component.ts
index 7224998..1e53c24 100644
--- a/frontend/src/app/question-shit/create-question/create-question.component.ts
+++ b/frontend/src/app/question-shit/create-question/create-question.component.ts
@@ -49,5 +49,4 @@ export class CreateQuestionComponent {
   onSelected(c) {
     this.selectedCategory = c;
   }
-
 }
diff --git a/frontend/src/app/question-shit/update-question/update-question.component.css b/frontend/src/app/question-shit/update-question/update-question.component.css
new file mode 100644
index 0000000..e69de29
diff --git a/frontend/src/app/question-shit/update-question/update-question.component.html b/frontend/src/app/question-shit/update-question/update-question.component.html
new file mode 100644
index 0000000..88cf75c
--- /dev/null
+++ b/frontend/src/app/question-shit/update-question/update-question.component.html
@@ -0,0 +1,23 @@
+<div class="z-10 relative">
+    <div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"></div>
+    <div class="fixed inset-0 z-10 overflow-y-auto">
+        <div class="flex flex-col min-h-full justify-center p-4 text-center items-center sm:p-0">
+            <div class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 ">
+                <h1 class="mt-2 mx-2 font-bold">Update Question</h1>
+
+                <form [formGroup]="updateQuestion" (ngSubmit)="onSubmit()" class="flex flex-col pb-2 mx-2">
+                    <input class="border-b-4 mt-2 w-full" type="text" placeholder="Text" formControlName="question">
+                    <select #select id="category" class="form-control" (change)="onSelected(select.value)">
+                        <option default value="">Theme</option>
+                        <option *ngFor="let c of categories" [value]="c.title">{{c.title}}</option>
+                    </select>
+                    <div class="flex flex-row justify-between">
+                        <button class="border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2" type="submit">Update</button>
+                        <button class="border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2" (click)="closeModal.emit()">Close</button>
+                    </div>
+                </form>
+
+            </div>
+        </div>
+    </div>
+</div>
\ No newline at end of file
diff --git a/frontend/src/app/question-shit/update-question/update-question.component.spec.ts b/frontend/src/app/question-shit/update-question/update-question.component.spec.ts
new file mode 100644
index 0000000..c6d6f68
--- /dev/null
+++ b/frontend/src/app/question-shit/update-question/update-question.component.spec.ts
@@ -0,0 +1,21 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { UpdateQuestionComponent } from './update-question.component';
+
+describe('UpdateQuestionComponent', () => {
+  let component: UpdateQuestionComponent;
+  let fixture: ComponentFixture<UpdateQuestionComponent>;
+
+  beforeEach(() => {
+    TestBed.configureTestingModule({
+      declarations: [UpdateQuestionComponent]
+    });
+    fixture = TestBed.createComponent(UpdateQuestionComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});
diff --git a/frontend/src/app/question-shit/update-question/update-question.component.ts b/frontend/src/app/question-shit/update-question/update-question.component.ts
new file mode 100644
index 0000000..a5de599
--- /dev/null
+++ b/frontend/src/app/question-shit/update-question/update-question.component.ts
@@ -0,0 +1,51 @@
+import { Component, EventEmitter, Input, Output } from '@angular/core';
+import { FormControl, FormGroup, Validators } from '@angular/forms';
+import { Category, Question, User } from 'src/app/Types/types';
+import { QuestionsService } from 'src/app/services/questions.service';
+import { UsersService } from 'src/app/services/users.service';
+
+@Component({
+  selector: 'app-update-question',
+  templateUrl: './update-question.component.html',
+  styleUrls: ['./update-question.component.css']
+})
+export class UpdateQuestionComponent {
+  updateQuestion: FormGroup;
+  private selectedCategory!: string;
+  categories!: Category[];
+
+  @Input() question!: Question;
+  @Output() closeModal: EventEmitter<void> = new EventEmitter<void>();
+
+  constructor(private questionController: QuestionsService) { }
+
+  ngOnInit(): void {
+
+    this.questionController.categories.subscribe(categoriesList => {
+      this.categories = categoriesList;
+    })
+
+    this.questionController.fetchCategories();
+
+    this.updateQuestion = new FormGroup({
+      question: new FormControl(this.question.question, Validators.required)
+    });
+  }
+
+  onSubmit() {
+    const question = this.updateQuestion.get("question")!.value;
+
+    const newQuestion: Question = {
+      id: this.question.id,
+      question: question,
+      category: this.selectedCategory
+    }
+
+    this.questionController.updateQuestion(newQuestion);
+    this.closeModal.emit();
+  }
+
+  onSelected(c) {
+    this.selectedCategory = c;
+  }
+}
diff --git a/frontend/src/app/services/questions.service.ts b/frontend/src/app/services/questions.service.ts
index 8f8f8df..516ef8d 100644
--- a/frontend/src/app/services/questions.service.ts
+++ b/frontend/src/app/services/questions.service.ts
@@ -1,6 +1,6 @@
 import { Injectable } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
-import { Category, Question } from '../Types/types';
+import { Answer, Category, Question } from '../Types/types';
 import { BehaviorSubject } from 'rxjs';
 
 const ROUTE = "http://0.0.0.0:30992/API/v1"
@@ -12,25 +12,25 @@ export class QuestionsService {
 
   private _categories = new BehaviorSubject<Category[]>([]);
   private _questions = new BehaviorSubject<Question[]>([]);
+  private _answers = new BehaviorSubject<Answer[]>([]);
 
   constructor(
     private http: HttpClient) { }
 
-  deleteQuestion(question: Question) {
-    this.http.delete(ROUTE + "/question/" + question.id.toString()).subscribe(() => {
-      this.fetchQuestions();
-    });
-  }
-
-  get categories() {
-    return this._categories.asObservable();
-  }
+    
+    get categories() {
+      return this._categories.asObservable();
+    }
+    
+    get questions() {
+      return this._questions.asObservable();
+    }
 
-  get questions() {
-    return this._questions.asObservable();
-  }
-
-  fetchCategories() {
+    get answers() {
+      return this._answers.asObservable();
+    }
+    
+    fetchCategories() {
     this.http.get(ROUTE + "/category").subscribe(categories => {
       this._categories.next(categories as Category[])
     })
@@ -41,16 +41,46 @@ export class QuestionsService {
       this._questions.next(questions as Question[])
     })
   }
-
+  
+  fetchAnswers(questionID: number) {
+    this.http.get(ROUTE + "/answer/" + questionID.toString()).subscribe(answers => {
+      this._answers.next(answers as Answer[]);
+    })
+  }
+  
   addQuestion(question:Question) {
     this.http.post<Question>(ROUTE + "/question", question).subscribe(() => {
       this.fetchQuestions();
     });
   }
+  
+  addAnswer(answer: Answer) {
+    this.http.post<Answer>(ROUTE + "/answer", answer).subscribe(() => {
+      this.fetchAnswers(answer.id_question);
+    });
+  }
+  
+  deleteQuestion(question: Question) {
+    this.http.delete(ROUTE + "/question/" + question.id.toString()).subscribe(() => {
+      this.fetchQuestions();
+    });
+  }
+
+  deleteAnswer(answer: Answer) {
+    this.http.delete(ROUTE + "/answer/" + answer.id.toString()).subscribe(() => {
+      this.fetchAnswers(answer.id_question);
+    })
+  }
+
+  updateQuestion(question: Question) {
+    this.http.patch(ROUTE + "/question/" + question.id.toString(), question).subscribe(() => {
+      this.fetchQuestions();
+    })
+  }
 
   // addUser(user: User) {
-  //   this.http.post<User>(ROUTE, user).subscribe(res => {
-  //     this.auth.login(user.username, user.password);
-  //   });
-  // }
-}
+    //   this.http.post<User>(ROUTE, user).subscribe(res => {
+      //     this.auth.login(user.username, user.password);
+      //   });
+      // }
+    }
-- 
GitLab