Skip to content

Commit

Permalink
update frontend api call
Browse files Browse the repository at this point in the history
  • Loading branch information
maelys-buhler committed Apr 26, 2024
1 parent 25d59d1 commit 0ce4066
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
16 changes: 8 additions & 8 deletions frontend/src/api_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ 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;
}

/**
* 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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/AnswerForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/QuizView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ce4066

Please sign in to comment.