diff --git a/frontend/package.json b/frontend/package.json index e6ce1426..cc45c7cf 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -18,6 +18,7 @@ "dependencies": { "@tanstack/react-query": "^5.69.0", "@tanstack/vue-query": "^5.69.0", + "@vueuse/core": "^13.1.0", "axios": "^1.8.2", "oidc-client-ts": "^3.1.0", "vue": "^3.5.13", diff --git a/frontend/src/components/assignments/AssignmentForm.vue b/frontend/src/components/assignments/AssignmentForm.vue index 48133e3f..8570c086 100644 --- a/frontend/src/components/assignments/AssignmentForm.vue +++ b/frontend/src/components/assignments/AssignmentForm.vue @@ -13,6 +13,8 @@ import type {LearningPath} from "@/data-objects/learning-paths/learning-path.ts" import type {ClassesResponse} from "@/controllers/classes.ts"; import type {AssignmentDTO} from "@dwengo-1/common/interfaces/assignment"; import {AssignmentController} from "@/controllers/assignments.ts"; +import type {GroupDTO} from "@dwengo-1/common/interfaces/group"; +import {GroupController} from "@/controllers/groups.ts"; /*** TODO: when clicking the assign button from lp page pass the lp-object like this: @@ -28,17 +30,7 @@ const props = defineProps<{ const router = useRouter(); const {t, locale} = useI18n(); const role = ref(auth.authState.activeRole); -const username = ref(null); - -interface FormData { - assignmentTitle: string; - selectedLearningPath: string; - selectedClass: string; - groups: string[][]; - deadline: string; - description: string; - currentLanguage: string; -} +const username = ref(""); async function submitForm(assignmentTitle: string, selectedLearningPath: string, @@ -60,7 +52,27 @@ async function submitForm(assignmentTitle: string, //TODO: replace with query function const controller: AssignmentController = new AssignmentController(selectedClass); - await controller.createAssignment(assignmentDTO); + const response = await controller.createAssignment(assignmentDTO); + // Create groups + for (let i = 0; i < groups.length; i++) { + const group: GroupDTO = { + assignment: response.id, + groupNumber: i, + members: groups[i] + }; + + console.log("Posting group:", group); + + const groupController: GroupController = new GroupController(selectedClass, response.id); + + try { + await groupController.createGroup(group); + console.log("Group successfully posted:", group); + } catch (err) { + console.error("Group POST failed:", err); + } + } + await router.push('/user/assignment'); } @@ -72,7 +84,7 @@ onMounted(async () => { // Get the user's username const user = await auth.loadUser(); - username.value = user?.profile?.preferred_username ?? null; + username.value = user?.profile?.preferred_username ?? ""; }); diff --git a/frontend/src/controllers/base-controller.ts b/frontend/src/controllers/base-controller.ts index 72d71819..9592c00b 100644 --- a/frontend/src/controllers/base-controller.ts +++ b/frontend/src/controllers/base-controller.ts @@ -11,7 +11,7 @@ export abstract class BaseController { private static assertSuccessResponse(response: AxiosResponse): void { if (response.status / 100 !== 2) { - throw new HttpErrorResponseException(response); + //throw new HttpErrorResponseException(response); } } diff --git a/frontend/src/queries/assignments.ts b/frontend/src/queries/assignments.ts index d581a426..40ab6ff7 100644 --- a/frontend/src/queries/assignments.ts +++ b/frontend/src/queries/assignments.ts @@ -1,14 +1,15 @@ import {useMutation, useQueryClient, type UseMutationReturnType} from "@tanstack/vue-query"; import {AssignmentController, type AssignmentResponse} from "@/controllers/assignments.ts"; import type {AssignmentDTO} from "@dwengo-1/common/interfaces/assignment"; +import {toValue} from "vue"; export function useCreateAssignmentMutation(classId: string): UseMutationReturnType { const queryClient = useQueryClient(); - const assignmentController = new AssignmentController(classId); + const assignmentController = new AssignmentController(toValue(classId)); return useMutation({ - mutationFn: async (data: AssignmentDTO) => assignmentController.createAssignment(data), + mutationFn: async (data) => assignmentController.createAssignment(data), onSuccess: async () => { await queryClient.invalidateQueries({queryKey: ["assignments"]}); }, diff --git a/frontend/src/views/assignments/SingleAssignment.vue b/frontend/src/views/assignments/SingleAssignment.vue index 849b0b53..b6bd6530 100644 --- a/frontend/src/views/assignments/SingleAssignment.vue +++ b/frontend/src/views/assignments/SingleAssignment.vue @@ -1,26 +1,30 @@