From 95715728e4ec4bde2c212026c96d867f8c928387 Mon Sep 17 00:00:00 2001 From: Timo De Meyst Date: Thu, 24 Apr 2025 01:07:29 +0200 Subject: [PATCH] feat: submit vraag (POST response zegt dat hier nog een fout zit) --- .../views/learning-paths/LearningPathPage.vue | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/frontend/src/views/learning-paths/LearningPathPage.vue b/frontend/src/views/learning-paths/LearningPathPage.vue index d311f36f..5de19524 100644 --- a/frontend/src/views/learning-paths/LearningPathPage.vue +++ b/frontend/src/views/learning-paths/LearningPathPage.vue @@ -13,13 +13,14 @@ import authService from "@/services/auth/auth-service.ts"; import { LearningPathNode } from "@/data-objects/learning-paths/learning-path-node.ts"; import LearningPathGroupSelector from "@/views/learning-paths/LearningPathGroupSelector.vue"; - import { useQuestionsQuery } from "@/queries/questions"; + import { useCreateQuestionMutation, useQuestionsQuery } from "@/queries/questions"; import type { QuestionsResponse } from "@/controllers/questions"; import type { LearningObjectIdentifierDTO } from "@dwengo-1/common/interfaces/learning-content"; import QandA from "@/components/QandA.vue"; - import type { QuestionDTO } from "@dwengo-1/common/interfaces/question"; - import {useStudentAssignmentsQuery} from "@/queries/students" + import type { QuestionData, QuestionDTO } from "@dwengo-1/common/interfaces/question"; + import {useStudentAssignmentsQuery, useStudentGroupsQuery} from "@/queries/students" import type { AssignmentDTO } from "@dwengo-1/common/interfaces/assignment"; +import type { GroupDTO } from "@dwengo-1/common/interfaces/group"; const router = useRouter(); const route = useRoute(); @@ -153,10 +154,39 @@ assignment.language === props.language ); }); - + + const loID:LearningObjectIdentifierDTO = { + hruid: props.learningObjectHruid as string, + language: props.language + } + const createQuestionMutation = useCreateQuestionMutation(loID) + const groupsQueryResult = useStudentGroupsQuery(authService.authState.user?.profile.preferred_username) + + const questionInput = ref(""); + function submitQuestion() { - // Replace with actual submission logic - alert(`Submitted`); + const assignments = studentAssignmentsQueryResult.data.value?.assignments as AssignmentDTO[] + const assignment = assignments.find( + (assignment) => + assignment.learningPath === props.hruid && + assignment.language === props.language + ) + const groups = groupsQueryResult.data.value?.groups as GroupDTO[] + const group = groups?.find(group => group.assignment === assignment?.id) as GroupDTO + const questionData:QuestionData = { + author: authService.authState.user?.profile.preferred_username, + content: questionInput.value, + inGroup: group //TODO: POST response zegt dat dit null is??? + } + createQuestionMutation.mutate(questionData, { + onSuccess: () => { + questionInput.value = "question:..."; // Clear the input field after submission + }, + onError: (e) => { + console.error(e) + questionInput.value = ""; // Clear the input field after submission + }, + }) } @@ -284,6 +314,7 @@ type="text" placeholder="question : ..." class="question-input" + v-model="questionInput" />