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

Merge branch 'main' into 'display-for-user'

# Conflicts:
#   FullstackProsjekt/src/frontend/src/components/shared/create-quiz/EditQuizView.vue
parents 7da7fd4e f05232c1
No related branches found
No related tags found
1 merge request!31Display for user
Pipeline #269327 passed
...@@ -22,6 +22,8 @@ import java.util.stream.Collectors; ...@@ -22,6 +22,8 @@ import java.util.stream.Collectors;
public class QuizController { public class QuizController {
private final QuizService quizService; private final QuizService quizService;
private static final Logger logger = LoggerFactory.getLogger(AuthenticationController.class);
@Autowired @Autowired
public QuizController(QuizService quizService) { public QuizController(QuizService quizService) {
...@@ -41,9 +43,9 @@ public class QuizController { ...@@ -41,9 +43,9 @@ public class QuizController {
return quizService.updateQuiz(quizDTO); return quizService.updateQuiz(quizDTO);
} }
@PostMapping("/delete") @PostMapping("/delete/{quizId}")
public void deleteQuiz(@RequestBody Map<String, Integer> payload) { public void deleteQuiz(@PathVariable Integer quizId) {
quizService.deleteQuiz(payload.get("id")); quizService.deleteQuiz(quizId);
} }
@GetMapping("/quiz/{quizId}") @GetMapping("/quiz/{quizId}")
...@@ -82,9 +84,11 @@ public class QuizController { ...@@ -82,9 +84,11 @@ public class QuizController {
public QuizDTO convertToDTO(Quiz quiz) { public QuizDTO convertToDTO(Quiz quiz) {
QuizDTO quizDTO = new QuizDTO(); QuizDTO quizDTO = new QuizDTO();
quizDTO.setCreatorId(quiz.getCreator().getId());
quizDTO.setId(quiz.getId()); quizDTO.setId(quiz.getId());
quizDTO.setTitle(quiz.getTitle()); quizDTO.setTitle(quiz.getTitle());
quizDTO.setCategory(quiz.getCategory()); quizDTO.setCategory(quiz.getCategory());
quizDTO.setDifficulty(quiz.getDifficulty());
return quizDTO; return quizDTO;
} }
......
<script> <script>
import { apiClient } from "@/api.js"; import { apiClient } from "@/api.js";
import { typeEnums } from "@/data/type.js"
export default { export default {
props: { props: {
quizId: { quizId: {
...@@ -12,31 +14,36 @@ export default { ...@@ -12,31 +14,36 @@ export default {
questionText: '', questionText: '',
answers: [{ text: '', correct: false }], answers: [{ text: '', correct: false }],
correctAnswerIndex: 0, correctAnswerIndex: 0,
type: 'MC', type: 'MULTIPLE_CHOICE',
score: 0, score: 0,
correctAnswer: null, correctAnswer: null,
errorMsg: '' errorMsg: '',
selectedType: null,
questionTypes: typeEnums
} }
}, },
methods: { methods: {
//TODO: error prevention/handling async submitForm() {
async handleSubmit() {
try { try {
this.findCorrectAnswer(); this.findCorrectAnswer();
await apiClient.post('/questions', { const data = {
quizId: this.quizId, quizId: this.quizId,
questionText: this.questionText, questionText: this.questionText,
type: this.type, type: this.selectedType,
answer: this.correctAnswer, answer: this.correctAnswer,
options: this.answers.map(answer => answer.text), //just the strings! options: this.answers.map(answer => answer.text),
score: this.score score: this.score,
//add questionId to questions in editQuiz! };
console.log(data);
}) await apiClient.post('/questions/save', data);
} catch (error) { } catch (error) {
this.errorMsg = 'Error signing up'; this.errorMsg = 'Error signing up';
} }
}, },
async handleSubmit() {
await this.submitForm();
this.$emit('close');
},
closeModal() { closeModal() {
this.$emit('close'); this.$emit('close');
}, },
...@@ -49,7 +56,6 @@ export default { ...@@ -49,7 +56,6 @@ export default {
} }
} }
} }
}; };
</script> </script>
...@@ -57,15 +63,20 @@ export default { ...@@ -57,15 +63,20 @@ export default {
<div class="modal-overlay" @click="closeModal"> <div class="modal-overlay" @click="closeModal">
<div @click.stop class="modal-mask"> <div @click.stop class="modal-mask">
<div class="modal-container"> <div class="modal-container">
<form @submit.prevent="handleSubmit"> <form @submit.prevent="submitForm">
<div class="question-title"> <div class="question-title">
<h3>Question:</h3> <h3>Question:</h3>
<input v-model="questionText" placeholder="Type your question here"> <input v-model="questionText" placeholder="Type your question here">
<label>Score:</label> <label>Score:</label>
<input type="number" id="scoreInput" v-model="score"> <input type="number" id="scoreInput" v-model="score">
</div> </div>
<div class="modal-body"> <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" <AnswerCard answer-id="answerCard" v-for="answer in answers"
:key="answer.id" :answerId="answer.id" :answer="answer.answer" :correct="answer.correct"/> :key="answer.id" :answerId="answer.id" :answer="answer.answer" :correct="answer.correct"/>
...@@ -89,8 +100,8 @@ export default { ...@@ -89,8 +100,8 @@ export default {
</table> </table>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="edit-btn" @click="newAnswer">Add answer</button> <button class="edit-btn" @click.prevent="newAnswer">Add answer</button>
<button class="modal-default-button" @click="$emit('close')">SUBMIT</button> <button type="submit" class="modal-default-button" @click.prevent="handleSubmit">SUBMIT</button>
</div> </div>
</form> </form>
</div> </div>
......
...@@ -27,7 +27,6 @@ export default { ...@@ -27,7 +27,6 @@ export default {
creatorId: null, creatorId: null,
quizId: null, quizId: null,
quizTitle: '', quizTitle: '',
questions: [], //question list is just a list of q-ids!!
category: '', category: '',
difficulty: '', difficulty: '',
errorMsg: '' errorMsg: ''
...@@ -43,11 +42,11 @@ export default { ...@@ -43,11 +42,11 @@ export default {
console.log('Fetching data for quiz: ', quizId); console.log('Fetching data for quiz: ', quizId);
try { try {
apiClient.get('/quiz/quiz/' + this.quizId).then(response => { apiClient.get('/quiz/quiz/' + this.quizId).then(response => {
console.log(response)
this.quizTitle = JSON.parse(response.data.title); this.quizTitle = JSON.parse(response.data.title);
this.questions = JSON.parse(JSON.stringify(response.data.questions));
this.creatorId = JSON.parse(response.data.creatorId); this.creatorId = JSON.parse(response.data.creatorId);
this.category = JSON.parse(response.data.category); this.category = response.data.category;
this.difficulty = JSON.parse(response.data.difficulty); this.difficulty = response.data.difficulty;
}); });
} catch (error) { } catch (error) {
//TODO: proper error handling //TODO: proper error handling
...@@ -63,7 +62,7 @@ export default { ...@@ -63,7 +62,7 @@ export default {
//TODO: questions answers, +question count //TODO: questions answers, +question count
}, },
deleteQuiz() { deleteQuiz() {
//API req, quizId apiClient.post('/quiz/delete/' + this.quizId)
} }
}, },
}; };
...@@ -161,11 +160,31 @@ async function submitQuestion() { ...@@ -161,11 +160,31 @@ async function submitQuestion() {
<QuestionCard v-for="question in questions" :question-id=question.id <QuestionCard v-for="question in questions" :question-id=question.id
:key="question.id"/> :key="question.id"/>
</div> </div>
<NewQuestionModel v-if="showNewQuestion" @close="hideNewQuestion" quiz-id="this.quizId"/> <NewQuestionModel v-if="showNewQuestion" @close="hideNewQuestion" :quizId=this.quizId></NewQuestionModel>
<!--
<div class="question-table">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Question</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>What is Vue?</td>
<td>
<button class="play-btn">View</button>
<button class="edit-btn">Edit</button>
<button class="delete-btn"> Delete</button>
</td>
</tr>
<div class="footer"> <div class="footer">
<button @click="newQuestion" class="add-Btn"> Add Question </button> <button @click="newQuestion" class="add-Btn"> Add Question </button>
<button class="delete-btn"> DELETE QUIZ </button> <button @click="deleteQuiz" class="delete-btn"> DELETE QUIZ </button>
<button class="save-Btn"> SAVE QUIZ </button> <button class="save-Btn"> SAVE QUIZ </button>
</div> </div>
</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