diff --git a/FullstackProsjekt/src/backend/main/java/edu/ntnu/idatt2105/controller/QuizController.java b/FullstackProsjekt/src/backend/main/java/edu/ntnu/idatt2105/controller/QuizController.java index 0477174f18efc1d2388284e721815bcefadd109b..6935d07efd420bbb5a49437d4ed158515b9e0fa4 100644 --- a/FullstackProsjekt/src/backend/main/java/edu/ntnu/idatt2105/controller/QuizController.java +++ b/FullstackProsjekt/src/backend/main/java/edu/ntnu/idatt2105/controller/QuizController.java @@ -22,8 +22,6 @@ import java.util.stream.Collectors; public class QuizController { private final QuizService quizService; - private static final Logger logger = LoggerFactory.getLogger(AuthenticationController.class); - @Autowired public QuizController(QuizService quizService) { @@ -43,9 +41,9 @@ public class QuizController { return quizService.updateQuiz(quizDTO); } - @PostMapping("/delete/{quizId}") - public void deleteQuiz(@PathVariable Integer quizId) { - quizService.deleteQuiz(quizId); + @PostMapping("/delete") + public void deleteQuiz(@RequestBody Map<String, Integer> payload) { + quizService.deleteQuiz(payload.get("id")); } @GetMapping("/quiz/{quizId}") @@ -84,11 +82,9 @@ public class QuizController { public QuizDTO convertToDTO(Quiz quiz) { QuizDTO quizDTO = new QuizDTO(); - quizDTO.setCreatorId(quiz.getCreator().getId()); quizDTO.setId(quiz.getId()); quizDTO.setTitle(quiz.getTitle()); quizDTO.setCategory(quiz.getCategory()); - quizDTO.setDifficulty(quiz.getDifficulty()); return quizDTO; } diff --git a/FullstackProsjekt/src/frontend/src/components/shared/NewQuestionModel.vue b/FullstackProsjekt/src/frontend/src/components/shared/NewQuestionModel.vue index 2415f1bb7a6aca4f76a6d136756d27824c0ff8f1..b502ac6b73757b77db8798c8b99c021dd75cb282 100644 --- a/FullstackProsjekt/src/frontend/src/components/shared/NewQuestionModel.vue +++ b/FullstackProsjekt/src/frontend/src/components/shared/NewQuestionModel.vue @@ -1,7 +1,5 @@ <script> -import { apiClient } from "@/api.js"; -import { typeEnums } from "@/data/type.js" - +import {apiClient} from "@/api.js"; export default { props: { quizId: { @@ -14,48 +12,44 @@ export default { questionText: '', answers: [{ text: '', correct: false }], correctAnswerIndex: 0, - type: 'MULTIPLE_CHOICE', + type: 'MC', score: 0, correctAnswer: null, - errorMsg: '', - selectedType: null, - questionTypes: typeEnums + errorMsg: '' } }, methods: { - async submitForm() { + //TODO: error prevention/handling + async handleSubmit() { try { this.findCorrectAnswer(); - const data = { + await apiClient.post('/questions', { quizId: this.quizId, questionText: this.questionText, - type: this.selectedType, + type: this.type, answer: this.correctAnswer, - options: this.answers.map(answer => answer.text), - score: this.score, - }; - console.log(data); - await apiClient.post('/questions/save', data); + options: this.answers.map(answer => answer.text), //just the strings! + score: this.score + //add questionId to questions in editQuiz! + + }) } catch (error) { this.errorMsg = 'Error signing up'; } }, - async handleSubmit() { - await this.submitForm(); - this.$emit('close'); - }, closeModal() { this.$emit('close'); }, newAnswer() { this.answers.push({ text: '', correct: false }); }, - findCorrectAnswer() { + findCorrectAnswer(){ if (this.correctAnswerIndex !== null && this.answers[this.correctAnswerIndex]) { this.correctAnswer = this.answers[this.correctAnswerIndex].text; } } } + }; </script> @@ -63,20 +57,15 @@ export default { <div class="modal-overlay" @click="closeModal"> <div @click.stop class="modal-mask"> <div class="modal-container"> - <form @submit.prevent="submitForm"> + <form @submit.prevent="handleSubmit"> <div class="question-title"> <h3>Question:</h3> <input v-model="questionText" placeholder="Type your question here"> - <label>Score:</label> <input type="number" id="scoreInput" v-model="score"> - </div> <div class="modal-body"> - <select v-model="selectedType"> - <option v-for="type in questionTypes" :key="type" :value="type">{{type}}</option> - </select> <!-- <AnswerCard answer-id="answerCard" v-for="answer in answers" :key="answer.id" :answerId="answer.id" :answer="answer.answer" :correct="answer.correct"/> @@ -100,8 +89,8 @@ export default { </table> </div> <div class="modal-footer"> - <button class="edit-btn" @click.prevent="newAnswer">Add answer</button> - <button type="submit" class="modal-default-button" @click.prevent="handleSubmit">SUBMIT</button> + <button class="edit-btn" @click="newAnswer">Add answer</button> + <button class="modal-default-button" @click="$emit('close')">SUBMIT</button> </div> </form> </div> diff --git a/FullstackProsjekt/src/frontend/src/components/shared/create-quiz/EditQuizView.vue b/FullstackProsjekt/src/frontend/src/components/shared/create-quiz/EditQuizView.vue index e441809449f5f69551d1362a603e4e9ee6ff003b..49df03999c451f5c6292d68a079a3cd873c73c6b 100644 --- a/FullstackProsjekt/src/frontend/src/components/shared/create-quiz/EditQuizView.vue +++ b/FullstackProsjekt/src/frontend/src/components/shared/create-quiz/EditQuizView.vue @@ -27,6 +27,7 @@ export default { creatorId: null, quizId: null, quizTitle: '', + questions: [], //question list is just a list of q-ids!! category: '', difficulty: '', errorMsg: '' @@ -42,11 +43,11 @@ export default { console.log('Fetching data for quiz: ', quizId); try { apiClient.get('/quiz/quiz/' + this.quizId).then(response => { - console.log(response) this.quizTitle = JSON.parse(response.data.title); + this.questions = JSON.parse(JSON.stringify(response.data.questions)); this.creatorId = JSON.parse(response.data.creatorId); - this.category = response.data.category; - this.difficulty = response.data.difficulty; + this.category = JSON.parse(response.data.category); + this.difficulty = JSON.parse(response.data.difficulty); }); } catch (error) { //TODO: proper error handling @@ -62,7 +63,7 @@ export default { //TODO: questions answers, +question count }, deleteQuiz() { - apiClient.post('/quiz/delete/' + this.quizId) + //API req, quizId } }, }; @@ -160,7 +161,7 @@ async function submitQuestion() { <QuestionCard v-for="question in questions" :question-id=question.id :key="question.id"/> </div> - <NewQuestionModel v-if="showNewQuestion" @close="hideNewQuestion" :quizId=this.quizId></NewQuestionModel> + <NewQuestionModel v-if="showNewQuestion" @close="hideNewQuestion" quiz-id="this.quizId"/> <!-- <div class="question-table"> <table class="table"> @@ -184,7 +185,7 @@ async function submitQuestion() { <div class="footer"> <button @click="newQuestion" class="add-Btn"> Add Question </button> - <button @click="deleteQuiz" class="delete-btn"> DELETE QUIZ </button> + <button class="delete-btn"> DELETE QUIZ </button> <button class="save-Btn"> SAVE QUIZ </button> </div> </div> diff --git a/FullstackProsjekt/src/frontend/src/data/type.js b/FullstackProsjekt/src/frontend/src/data/type.js deleted file mode 100644 index 8376fa6182ab5fb85029e906a7b2916720876856..0000000000000000000000000000000000000000 --- a/FullstackProsjekt/src/frontend/src/data/type.js +++ /dev/null @@ -1,5 +0,0 @@ -export const typeEnums = [ - "MULTIPLE_CHOICE", - 'TRUE_OR_FALSE', - 'STRING' -]; \ No newline at end of file