Skip to content
Snippets Groups Projects
Commit 365cf84e authored by Madeleine Stenberg Jonassen's avatar Madeleine Stenberg Jonassen
Browse files

Revert "Merge branch 'backend-frontend-sync' into 'main'"

This reverts merge request !30
parent d3e2f9e4
No related branches found
No related tags found
No related merge requests found
Pipeline #269335 passed
......@@ -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;
}
......
<script>
import {apiClient} from "@/api.js";
import { typeEnums } from "@/data/type.js"
export default {
props: {
quizId: {
......@@ -14,36 +12,31 @@ 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');
},
......@@ -56,6 +49,7 @@ export default {
}
}
}
};
</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>
......
......@@ -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>
......
export const typeEnums = [
"MULTIPLE_CHOICE",
'TRUE_OR_FALSE',
'STRING'
];
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment