From 0ce406646e72206f666818ac5ea985474877b1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=BChler=20Ma=C3=ABlys?= Date: Fri, 26 Apr 2024 09:57:02 +0200 Subject: [PATCH] update frontend api call --- frontend/src/api_client.js | 16 ++++++++-------- frontend/src/components/AnswerForm.vue | 9 ++++++--- frontend/src/views/QuizView.vue | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/frontend/src/api_client.js b/frontend/src/api_client.js index bad015c..d7f5184 100644 --- a/frontend/src/api_client.js +++ b/frontend/src/api_client.js @@ -53,8 +53,8 @@ export default * Get if the user has already asked for options * @returns {Boolean} true if options have been asked, false otherwise */ - static async getIfOptionsAsked() { - const response = await axios.get(`/api/question/options_asked`); + static async getIfOptionsAsked(category_id) { + const response = await axios.get(`/api/question/${category_id}/options_asked`); return !!response.data.options_asked; } @@ -62,8 +62,8 @@ export default * Get the options for the current question * @returns {Object} {"id_option": "text_option"} */ - static async getOptions() { - const response = await axios.get(`/api/question/options`); + static async getOptions(category_id) { + const response = await axios.get(`/api/question/${category_id}/options`); return response.data.options; } @@ -138,8 +138,8 @@ export default * @param {String} answer_text * @returns {Object} {user_is_correct: Boolean, right_answer: String, answer_sent: String} */ - static async postAnswerText(answer_text) { - const response = await axios.post(`/api/question/answer_text/`, { + static async postAnswerText(answer_text, category_id) { + const response = await axios.post(`/api/question/${category_id}/answer_text/`, { answer: answer_text, }); return response.data; @@ -150,8 +150,8 @@ export default * @param {String} option_id * @returns {Object} {user_is_correct: Boolean, right_answer: String, answer_sent: String} */ - static async postAnswerOption(option_id) { - const response = await axios.post(`/api/question/answer_option/`, { + static async postAnswerOption(option_id, category_id) { + const response = await axios.post(`/api/question/${category_id}/answer_option/`, { answer: option_id, }); return response.data; diff --git a/frontend/src/components/AnswerForm.vue b/frontend/src/components/AnswerForm.vue index 9722cb8..24ef598 100644 --- a/frontend/src/components/AnswerForm.vue +++ b/frontend/src/components/AnswerForm.vue @@ -2,8 +2,11 @@ import APIClient from '@/api_client'; import { defineEmits, onMounted, ref, defineProps, watch } from 'vue'; import AnswerMessage from '@/components/AnswerMessage.vue'; +import {useRoute} from "vue-router"; // variables specific to this component +const route = useRoute() +const id_category = route.params.id_category; const emit = defineEmits(['newQuestion', 'updateUserIq']) const answer_sent = ref(false); const show_text_form = ref(true); @@ -21,20 +24,20 @@ const props = defineProps({ }) const submitAnswerText = async () => { - response_to_answer.value = await APIClient.postAnswerText(answer_text.value); + response_to_answer.value = await APIClient.postAnswerText(answer_text.value, id_category); answer_sent.value = true; emit('updateUserIq'); } const submitAnswerOption = async (id) => { - response_to_answer.value = await APIClient.postAnswerOption(id); + response_to_answer.value = await APIClient.postAnswerOption(id, id_category); answer_sent.value = true; emit('updateUserIq'); } const fetchOptions = async () => { show_text_form.value = false; - options.value = await APIClient.getOptions(); + options.value = await APIClient.getOptions(id_category); } const newQuestion = () => { diff --git a/frontend/src/views/QuizView.vue b/frontend/src/views/QuizView.vue index 248237f..c79a03b 100644 --- a/frontend/src/views/QuizView.vue +++ b/frontend/src/views/QuizView.vue @@ -20,7 +20,7 @@ const fetchNewQuestion = async () => { question.value = await APIClient.getNewQuestion(id_category); // wait for the question before checking if the user has asked for options - hasAskedOptions.value = await APIClient.getIfOptionsAsked(); + hasAskedOptions.value = await APIClient.getIfOptionsAsked(id_category); }; // Fetch user IQ and add it to the graph