diff --git a/backend/src/main/java/com/odde/doughnut/controllers/PredefinedQuestionController.java b/backend/src/main/java/com/odde/doughnut/controllers/PredefinedQuestionController.java index b6929320a7..3a75fc1aa1 100644 --- a/backend/src/main/java/com/odde/doughnut/controllers/PredefinedQuestionController.java +++ b/backend/src/main/java/com/odde/doughnut/controllers/PredefinedQuestionController.java @@ -122,6 +122,27 @@ public PredefinedQuestion toggleApproval( return predefinedQuestionService.toggleApproval(predefinedQuestion); } + @PatchMapping("/{predefinedQuestion}") + @Transactional + public PredefinedQuestion updateQuestion( + @PathVariable("predefinedQuestion") @Schema(type = "integer") + PredefinedQuestion predefinedQuestion, + @Valid @RequestBody PredefinedQuestion updatedQuestion) + throws UnexpectedNoAccessRightException { + authorizationService.assertAuthorization(predefinedQuestion.getNote()); + return predefinedQuestionService.updateQuestion(predefinedQuestion, updatedQuestion); + } + + @PostMapping("/{predefinedQuestion}/delete") + @Transactional + public void deleteQuestion( + @PathVariable("predefinedQuestion") @Schema(type = "integer") + PredefinedQuestion predefinedQuestion) + throws UnexpectedNoAccessRightException { + authorizationService.assertAuthorization(predefinedQuestion.getNote()); + predefinedQuestionService.deleteQuestion(predefinedQuestion); + } + @GetMapping(value = "/{note}/export-question-generation", produces = "application/json") public Map exportQuestionGeneration( @PathVariable("note") @Schema(type = "integer") Note note) diff --git a/backend/src/main/java/com/odde/doughnut/services/PredefinedQuestionService.java b/backend/src/main/java/com/odde/doughnut/services/PredefinedQuestionService.java index 71865ca289..e4737c879f 100644 --- a/backend/src/main/java/com/odde/doughnut/services/PredefinedQuestionService.java +++ b/backend/src/main/java/com/odde/doughnut/services/PredefinedQuestionService.java @@ -53,6 +53,18 @@ public PredefinedQuestion toggleApproval(PredefinedQuestion question) { return question; } + public PredefinedQuestion updateQuestion( + PredefinedQuestion question, PredefinedQuestion updatedQuestion) { + question.setMultipleChoicesQuestion(updatedQuestion.getMultipleChoicesQuestion()); + question.setCorrectAnswerIndex(updatedQuestion.getCorrectAnswerIndex()); + entityPersister.save(question); + return question; + } + + public void deleteQuestion(PredefinedQuestion question) { + entityPersister.remove(question); + } + public QuestionContestResult contest(PredefinedQuestion predefinedQuestion) { MCQWithAnswer mcqWithAnswer = predefinedQuestion.getMcqWithAnswer(); QuestionEvaluation questionContestResult = diff --git a/frontend/src/components/notes/QuestionManagement.vue b/frontend/src/components/notes/QuestionManagement.vue index d1d333f929..5a462bb979 100644 --- a/frontend/src/components/notes/QuestionManagement.vue +++ b/frontend/src/components/notes/QuestionManagement.vue @@ -1,26 +1,163 @@