diff --git a/frontend/src/composables/services/admins.service.ts b/frontend/src/composables/services/admins.service.ts index ca25e700..7c5191f4 100644 --- a/frontend/src/composables/services/admins.service.ts +++ b/frontend/src/composables/services/admins.service.ts @@ -2,32 +2,35 @@ import {Admin} from '@/types/Admin.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useAdmin() { const admins = ref(null); const admin = ref(null); - const toast = useToast(); - async function getAdminByID(id: string, t: ComposerTranslation) { + async function getAdminByID(id: string) { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - get(endpoint, admin, Admin.fromJSON, toast, t); + await get(endpoint, admin, Admin.fromJSON); } - async function getAdmins(t: ComposerTranslation) { + async function getAdmins() { const endpoint = endpoints.admins.index; - getList(endpoint, admins, Admin.fromJSON, toast, t); + await getList(endpoint, admins, Admin.fromJSON); } - async function createAdmin(admin_data: any, t: ComposerTranslation) { + async function createAdmin(admin_data: Admin) { const endpoint = endpoints.admins.index; - create(endpoint, admin_data, admin, Admin.fromJSON, toast, t); + await create(endpoint, + { + email:admin_data.email, + first_name:admin_data.first_name, + last_name: admin_data.last_name + }, + admin, Admin.fromJSON); } - async function deleteAdmin(id: string, t: ComposerTranslation) { + async function deleteAdmin(id: string) { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - delete_id(endpoint, admin, Admin.fromJSON, toast, t); + await delete_id(endpoint, admin, Admin.fromJSON); } return { diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 6f698e41..f92e626d 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -3,48 +3,51 @@ import { Response } from '@/types/Response'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id, delete_id_with_data } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useAssistant() { const assistants = ref(null); const assistant = ref(null); const response = ref(null); - const toast = useToast(); - async function getAssistantByID(id: string, t: ComposerTranslation) { + async function getAssistantByID(id: string) { const endpoint = endpoints.assistants.retrieve.replace('{id}', id); - get(endpoint, assistant, Assistant.fromJSON, toast, t); + await get(endpoint, assistant, Assistant.fromJSON); } - async function getAssistantByCourse(course_id: string, t: ComposerTranslation) { + async function getAssistantByCourse(course_id: string) { const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id); - get(endpoint, assistant, Assistant.fromJSON, toast, t); + await get(endpoint, assistant, Assistant.fromJSON); } - async function getAssistants(t: ComposerTranslation) { + async function getAssistants() { const endpoint = endpoints.assistants.index; - getList(endpoint, assistants, Assistant.fromJSON, toast, t); + await getList(endpoint, assistants, Assistant.fromJSON); } - async function assistantJoinCourse(course_id: string, assistant_id: string, t: ComposerTranslation) { + async function assistantJoinCourse(course_id: string, assistant_id: string) { const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id); - create(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON, toast, t); + await create(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON); } - async function assistantLeaveCourse(course_id: string, assistant_id: string, t: ComposerTranslation) { + async function assistantLeaveCourse(course_id: string, assistant_id: string) { const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id); - delete_id_with_data(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON, toast, t); + await delete_id_with_data(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON); } - async function createAssistant(assistant_data: any, t: ComposerTranslation) { + async function createAssistant(assistant_data: Assistant) { const endpoint = endpoints.assistants.index; - create(endpoint, assistant_data, assistant, Assistant.fromJSON, toast, t); + await create(endpoint, + { + email:assistant_data.email, + first_name:assistant_data.first_name, + last_name: assistant_data.last_name + }, + assistant, Assistant.fromJSON); } - async function deleteAssistant(id: string, t: ComposerTranslation) { + async function deleteAssistant(id: string) { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - delete_id(endpoint, assistant, Assistant.fromJSON, toast, t); + await delete_id(endpoint, assistant, Assistant.fromJSON); } return { diff --git a/frontend/src/composables/services/courses.service.ts b/frontend/src/composables/services/courses.service.ts index 3d13270a..78c80705 100644 --- a/frontend/src/composables/services/courses.service.ts +++ b/frontend/src/composables/services/courses.service.ts @@ -2,42 +2,45 @@ import {Course} from '@/types/Course.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useCourses() { const courses = ref(null); const course = ref(null); - const toast = useToast(); - async function getCourseByID(id: string, t: ComposerTranslation) { + async function getCourseByID(id: string) { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await get(endpoint, course, Course.fromJSON, toast, t); + await get(endpoint, course, Course.fromJSON); } - async function getCourses(t: ComposerTranslation) { + async function getCourses() { const endpoint = endpoints.courses.index; - await getList(endpoint, courses, Course.fromJSON, toast, t); + await getList(endpoint, courses, Course.fromJSON); } - async function getCoursesByStudent(student_id: string, t: ComposerTranslation) { + async function getCoursesByStudent(student_id: string) { const endpoint = endpoints.courses.byStudent.replace('{student_id}', student_id); - await getList(endpoint, courses, Course.fromJSON, toast, t); + await getList(endpoint, courses, Course.fromJSON); } - async function createCourse(course_data: any, t: ComposerTranslation) { + async function createCourse(course_data: Course) { const endpoint = endpoints.courses.index; - await create(endpoint, course_data, course, Course.fromJSON, toast, t); + await create(endpoint, + { + name: course_data.name, + description: course_data.description, + academic_startyear: course_data.academic_startyear + }, + course, Course.fromJSON); } - async function cloneCourse(course_id: string, clone_assistants: boolean, t: ComposerTranslation) { + async function cloneCourse(course_id: string, clone_assistants: boolean) { const endpoint = endpoints.courses.clone.replace('{course_id}', course_id); - await create(endpoint, {clone_assistants: clone_assistants.toString() }, course, Course.fromJSON, toast, t); + await create(endpoint, {clone_assistants: clone_assistants.toString() }, course, Course.fromJSON); } - async function deleteCourse(id: string, t: ComposerTranslation) { + async function deleteCourse(id: string) { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await delete_id(endpoint, course, Course.fromJSON, toast, t); + await delete_id(endpoint, course, Course.fromJSON); } return { diff --git a/frontend/src/composables/services/faculties.service.ts b/frontend/src/composables/services/faculties.service.ts index a0be2a6b..50eb432e 100644 --- a/frontend/src/composables/services/faculties.service.ts +++ b/frontend/src/composables/services/faculties.service.ts @@ -2,32 +2,29 @@ import {Faculty} from '@/types/Faculty.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useFaculty() { const faculties = ref(null); const faculty = ref(null); - const toast = useToast(); - async function getFacultyByID(name: string, t: ComposerTranslation) { + async function getFacultyByID(name: string) { const endpoint = endpoints.faculties.retrieve.replace('{name}', name); - get(endpoint, faculty, Faculty.fromJSON, toast, t); + await get(endpoint, faculty, Faculty.fromJSON); } - async function getFacultys(t: ComposerTranslation) { + async function getFacultys() { const endpoint = endpoints.faculties.index; - getList(endpoint, faculties, Faculty.fromJSON, toast, t); + await getList(endpoint, faculties, Faculty.fromJSON); } - async function createFaculty(faculty_data: any, t: ComposerTranslation) { + async function createFaculty(faculty_data: Faculty) { const endpoint = endpoints.faculties.index; - create(endpoint, faculty_data, faculty, Faculty.fromJSON, toast, t); + await create(endpoint, {name: faculty_data.name}, faculty, Faculty.fromJSON); } - async function deleteFaculty(id: string, t: ComposerTranslation) { + async function deleteFaculty(id: string) { const endpoint = endpoints.faculties.retrieve.replace('{id}', id); - delete_id(endpoint, faculty, Faculty.fromJSON, toast, t); + await delete_id(endpoint, faculty, Faculty.fromJSON); } return { diff --git a/frontend/src/composables/services/groups.service.ts b/frontend/src/composables/services/groups.service.ts index b2cb3d93..4c7cf772 100644 --- a/frontend/src/composables/services/groups.service.ts +++ b/frontend/src/composables/services/groups.service.ts @@ -2,32 +2,33 @@ import {Group} from '@/types/Group.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useGroup() { const groups = ref(null); const group = ref(null); - const toast = useToast(); - async function getGroupByID(id: string, t: ComposerTranslation) { + async function getGroupByID(id: string) { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - get(endpoint, group, Group.fromJSON, toast, t); + await get(endpoint, group, Group.fromJSON); } - async function getGroupsByProject(project_id: string, t: ComposerTranslation) { + async function getGroupsByProject(project_id: string) { const endpoint = endpoints.groups.byProject.replace('{project_id}', project_id); - getList(endpoint, groups, Group.fromJSON, toast, t); + await getList(endpoint, groups, Group.fromJSON); } - async function createGroup(group_data: any, group_id: string, t: ComposerTranslation) { + async function createGroup(group_data: Group, group_id: string) { const endpoint = endpoints.groups.byProject.replace('{group_id}', group_id); - create(endpoint, group_data, group, Group.fromJSON, toast, t); + await create(endpoint, + { + score: group_data.score + }, + group, Group.fromJSON); } - async function deleteGroup(id: string, t: ComposerTranslation) { + async function deleteGroup(id: string) { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - delete_id(endpoint, group, Group.fromJSON, toast, t); + await delete_id(endpoint, group, Group.fromJSON); } return { diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index b798a68c..45d0f4a7 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -1,107 +1,98 @@ -import axios, { AxiosError, AxiosResponse } from 'axios'; +import { AxiosError, AxiosResponse } from 'axios'; +import { client } from '@/composables/axios.ts' import {Ref} from 'vue'; -import {ComposerTranslation} from "vue-i18n"; +import {useToastStore} from '@/store/toast.store.ts'; +import { i18n } from '../i18n'; const lifeTime = 3000; -export async function get(endpoint: string, ref: Ref, fromJson: (data: any) => T, toast:any, t: ComposerTranslation): Promise { - await axios.get(endpoint).then((response: AxiosResponse) => { +export async function get(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { + await client.get(endpoint).then((response: AxiosResponse) => { ref.value = fromJson(response.data); - //toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + //add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); }).catch((error: AxiosError) => { - processError(error, toast, t); + processError(error); console.error(error); // Log the error for debugging }); } -export async function create(endpoint: string, data:any, ref: Ref, fromJson: (data: any) => T, toast:any, t: ComposerTranslation): Promise { - const headers = { - // TODO change this to your token - Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQyODQwMjY1LCJpYXQiOjE3MTEzMDQyNjUsImp0aSI6ImQwYTgxY2YxMzU5NTQ4OWQ4OGNiZDFmZmZiMGI0MmJhIiwidXNlcl9pZCI6IjAwMDIwMTI0NzAxMSJ9.izGK0MStcMiPkOAWs0wgWsYEs0_5S1WvsleWaIcttnk" - }; - await axios.post(endpoint, data, { headers }).then((response: AxiosResponse) => { +export async function create(endpoint: string, data:any, ref: Ref, fromJson: (data: any) => T): Promise { + await client.post(endpoint, data).then((response: AxiosResponse) => { ref.value = fromJson(response.data); - //toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + //add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); }).catch((error: AxiosError) => { - processError(error, toast, t); + processError(error); console.error(error); // Log the error for debugging }); } -export async function delete_id(endpoint: string, ref: Ref, fromJson: (data: any) => T, toast:any, t: ComposerTranslation): Promise { - const headers = { - // TODO change this to your token - Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQyODQwMjY1LCJpYXQiOjE3MTEzMDQyNjUsImp0aSI6ImQwYTgxY2YxMzU5NTQ4OWQ4OGNiZDFmZmZiMGI0MmJhIiwidXNlcl9pZCI6IjAwMDIwMTI0NzAxMSJ9.izGK0MStcMiPkOAWs0wgWsYEs0_5S1WvsleWaIcttnk" - }; - await axios.delete(endpoint,{ headers }).then((response: AxiosResponse) => { +export async function delete_id(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { + await client.delete(endpoint).then((response: AxiosResponse) => { ref.value = fromJson(response.data); - //toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + //add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); }).catch((error: AxiosError) => { - processError(error, toast, t); + processError(error); console.error(error); // Log the error for debugging }); } -export async function delete_id_with_data(endpoint: string, data: any, ref: Ref, fromJson: (data: any) => T, toast:any, t: ComposerTranslation): Promise { - const headers = { - // TODO change this to your token - Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQyODQwMjY1LCJpYXQiOjE3MTEzMDQyNjUsImp0aSI6ImQwYTgxY2YxMzU5NTQ4OWQ4OGNiZDFmZmZiMGI0MmJhIiwidXNlcl9pZCI6IjAwMDIwMTI0NzAxMSJ9.izGK0MStcMiPkOAWs0wgWsYEs0_5S1WvsleWaIcttnk" - }; - await axios.delete(endpoint,{ headers, data }).then((response: AxiosResponse) => { +export async function delete_id_with_data(endpoint: string, data: any, ref: Ref, fromJson: (data: any) => T): Promise { + await client.delete(endpoint,{ data }).then((response: AxiosResponse) => { ref.value = fromJson(response.data); - //toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + //add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); }).catch((error: AxiosError) => { - processError(error, toast, t); + processError(error); console.error(error); // Log the error for debugging }); } -export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T, toast:any, t: ComposerTranslation): Promise { - await axios.get(endpoint).then(response => { +export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { + await client.get(endpoint).then(response => { ref.value = response.data.map((data: T) => fromJson(data)); - //toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + //add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); } ).catch((error: AxiosError) => { - processError(error, toast, t); + processError(error); console.error(error); // Log the error for debugging }); } -export async function getListMerged(endpoints: string[], ref: Ref, fromJson: (data: any) => T, toast:any, t: ComposerTranslation): Promise { - +export async function getListMerged(endpoints: string[], ref: Ref, fromJson: (data: any) => T): Promise { // Create an array to accumulate all response data const allData: T[] = []; for (const endpoint of endpoints){ console.log(endpoint) - await axios.get(endpoint).then(response => { + await client.get(endpoint).then(response => { const responseData: T[] = response.data.map((data: T) => fromJson(data)); allData.push(...responseData); // Merge into the allData array - // toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + // add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); } ).catch((error: AxiosError) => { - processError(error, toast, t); + processError(error); console.error(error); // Log the error for debugging }); } ref.value = allData; } -export function processError(error: AxiosError, toast:any, t: ComposerTranslation){ +export function processError(error: AxiosError){ + const { t } = i18n.global; + const { add } = useToastStore(); if (error.response) { // The request was made and the server responded with a status code if (error.response.status === 404) { - toast.add({ severity: 'error', summary: t('composables.helpers.errors.notFound'), detail: t('composables.helpers.errors.notFoundDetail'), life: lifeTime }); + add({ severity: 'error', summary: t('composables.helpers.errors.notFound'), detail: t('composables.helpers.errors.notFoundDetail'), life: lifeTime }); } else if (error.response.status === 401) { - toast.add({ severity: 'error', summary: t('composables.helpers.errors.unauthorized'), detail: t('composables.helpers.errors.unauthorizedDetail'), life: lifeTime }); + add({ severity: 'error', summary: t('composables.helpers.errors.unauthorized'), detail: t('composables.helpers.errors.unauthorizedDetail'), life: lifeTime }); } else { - toast.add({ severity: 'error', summary: t('composables.helpers.errors.server'), detail: t('composables.helpers.errors.serverDetail'), life: lifeTime }); + add({ severity: 'error', summary: t('composables.helpers.errors.server'), detail: t('composables.helpers.errors.serverDetail'), life: lifeTime }); } } else if (error.request) { // The request was made but no response was received - toast.add({ severity: 'error', summary: t('composables.helpers.errors.network'), detail: t('composables.helpers.errors.networkDetail'), life: lifeTime }); + add({ severity: 'error', summary: t('composables.helpers.errors.network'), detail: t('composables.helpers.errors.networkDetail'), life: lifeTime }); } else { // Something happened in setting up the request that triggered an error - toast.add({ severity: 'error', summary: t('composables.helpers.errors.request'), detail: t('composables.helpers.errors.requestDetail'), life: lifeTime }); + add({ severity: 'error', summary: t('composables.helpers.errors.request'), detail: t('composables.helpers.errors.requestDetail'), life: lifeTime }); } } \ No newline at end of file diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index f23af127..487ab4b6 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -4,43 +4,40 @@ import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import axios from 'axios'; import { get, getList, getListMerged, create, delete_id, processError } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useProject() { const projects = ref(null); const project = ref(null); - const toast = useToast(); - async function getProjectByID(id: string, t: ComposerTranslation) { + async function getProjectByID(id: string) { const endpoint = endpoints.projects.retrieve.replace('{id}', id); - get(endpoint, project, Project.fromJSON, toast, t); + await get(endpoint, project, Project.fromJSON); } - async function getProjectsByCourse(course_id: string, t: ComposerTranslation) { + async function getProjectsByCourse(course_id: string) { const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id); - getList(endpoint, projects, Project.fromJSON, toast, t); + await getList(endpoint, projects, Project.fromJSON); } - async function getProjectsByStudent(student_id: string, t: ComposerTranslation) { + async function getProjectsByStudent(student_id: string) { const endpoint = endpoints.courses.byStudent.replace('{student_id}', student_id); const courses = ref(null); - await getList(endpoint, courses, Course.fromJSON, toast, t); + await getList(endpoint, courses, Course.fromJSON); const endpList = []; for (const course of courses.value?courses.value:[]){ endpList.push(endpoints.projects.byCourse.replace('{course_id}', course.id.toString())); } - await getListMerged(endpList, projects, Project.fromJSON, toast, t); + await getListMerged(endpList, projects, Project.fromJSON); } - async function getProjectsByCourseAndDeadline(course_id: string, deadlineDate: Date, t: ComposerTranslation ) { + async function getProjectsByCourseAndDeadline(course_id: string, deadlineDate: Date ) { const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id); - axios.get(endpoint).then(response => { + await axios.get(endpoint).then(response => { const allProjects = response.data.map((projectData: Project) => Project.fromJSON(projectData)); // Filter projects based on the deadline date @@ -52,20 +49,33 @@ export function useProject() { // Update the projects ref with the filtered projects projects.value = projectsWithMatchingDeadline; }).catch(error => { - processError(error, toast, t); + processError(error); console.log(error.data); }); } - async function createProject(project_data: any, course_id: string, t: ComposerTranslation) { + async function createProject(project_data: Project, course_id: string) { const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id); - create(endpoint, project_data, project, Project.fromJSON, toast, t); + await create(endpoint, + { + name: project_data.name, + description: project_data.description, + visible: project_data.visible, + archived: project_data.archived, + locked_groups: project_data.locked_groups, + start_data: project_data.start_date, + deadline: project_data.deadline, + max_score: project_data.max_score, + score_visible: project_data.score_visible, + group_size: project_data.group_size + }, + project, Project.fromJSON); } - async function deleteProject(id: string, t: ComposerTranslation) { - const endpoint = endpoints.projects.retrieve.replace('{id}', id.toString()); - delete_id(endpoint, project, Project.fromJSON, toast, t); + async function deleteProject(id: string) { + const endpoint = endpoints.projects.retrieve.replace('{id}', id); + await delete_id(endpoint, project, Project.fromJSON); } return { diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index 7d4d4e28..ddb8b85d 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -2,32 +2,33 @@ import {Structure_check} from '@/types/Structure_check.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useStructure_check() { const structure_checks = ref(null); const structure_check = ref(null); - const toast = useToast(); - async function getStructure_checkByID(id: string, t: ComposerTranslation) { + async function getStructure_checkByID(id: string) { const endpoint = endpoints.structure_checks.retrieve.replace('{id}', id); - get(endpoint, structure_check, Structure_check.fromJSON, toast, t); + await get(endpoint, structure_check, Structure_check.fromJSON); } - async function getStructure_checkByProject(project_id: string, t: ComposerTranslation) { + async function getStructure_checkByProject(project_id: string) { const endpoint = endpoints.structure_checks.byProject.replace('{project_id}', project_id); - getList(endpoint, structure_checks, Structure_check.fromJSON, toast, t); + await getList(endpoint, structure_checks, Structure_check.fromJSON); } - async function createStructure_check(structure_check_data: any, project_id: string, t: ComposerTranslation) { + async function createStructure_check(structure_check_data: Structure_check, project_id: string) { const endpoint = endpoints.structure_checks.byProject.replace('{project_id}', project_id); - create(endpoint, structure_check_data, structure_check, Structure_check.fromJSON, toast, t); + await create(endpoint, + { + name: structure_check_data.name + }, + structure_check, Structure_check.fromJSON); } - async function deleteStructure_check(id: string, t: ComposerTranslation) { + async function deleteStructure_check(id: string) { const endpoint = endpoints.structure_checks.retrieve.replace('{id}', id); - delete_id(endpoint, structure_check, Structure_check.fromJSON, toast, t); + await delete_id(endpoint, structure_check, Structure_check.fromJSON); } return { diff --git a/frontend/src/composables/services/students.service.ts b/frontend/src/composables/services/students.service.ts index dbc85720..6fa31872 100644 --- a/frontend/src/composables/services/students.service.ts +++ b/frontend/src/composables/services/students.service.ts @@ -3,63 +3,66 @@ import { Response } from '@/types/Response'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id, delete_id_with_data } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useStudents() { const students = ref(null); const student = ref(null); const response = ref(null); - const toast = useToast(); - async function getStudentByID(id: string, t: ComposerTranslation) { + async function getStudentByID(id: string) { const endpoint = endpoints.students.retrieve.replace('{id}', id); - get(endpoint, student, Student.fromJSON, toast, t); + await get(endpoint, student, Student.fromJSON); } - async function getStudents(t: ComposerTranslation) { + async function getStudents() { const endpoint = endpoints.students.index; - getList(endpoint, students, Student.fromJSON, toast, t); + await getList(endpoint, students, Student.fromJSON); } - async function getStudentsbyCourse(course_id: string, t: ComposerTranslation) { + async function getStudentsbyCourse(course_id: string) { const endpoint = endpoints.students.byCourse.replace('{course_id}', course_id); - getList(endpoint, students, Student.fromJSON, toast, t); + await getList(endpoint, students, Student.fromJSON); } - async function getStudentsbyGroup(group_id: string, t: ComposerTranslation) { + async function getStudentsbyGroup(group_id: string) { const endpoint = endpoints.students.byGroup.replace('{group_id}', group_id); - getList(endpoint, students, Student.fromJSON, toast, t); + await getList(endpoint, students, Student.fromJSON); } - async function studentJoinCourse(course_id: string, student_id: string, t: ComposerTranslation) { + async function studentJoinCourse(course_id: string, student_id: string) { const endpoint = endpoints.students.byCourse.replace('{course_id}', course_id); - create(endpoint, {student_id: student_id}, response, Response.fromJSON, toast, t); + await create(endpoint, {student_id: student_id}, response, Response.fromJSON); } - async function studentLeaveCourse(course_id: string, student_id: string, t: ComposerTranslation) { + async function studentLeaveCourse(course_id: string, student_id: string) { const endpoint = endpoints.students.byCourse.replace('{course_id}', course_id); - delete_id_with_data(endpoint, {student_id: student_id}, response, Response.fromJSON, toast, t); + await delete_id_with_data(endpoint, {student_id: student_id}, response, Response.fromJSON); } - async function studentJoinGroup(group_id: string, student_id: string, t: ComposerTranslation) { + async function studentJoinGroup(group_id: string, student_id: string) { const endpoint = endpoints.students.byGroup.replace('{group_id}', group_id); - create(endpoint, {student_id: student_id}, response, Response.fromJSON, toast, t); + await create(endpoint, {student_id: student_id}, response, Response.fromJSON); } - async function studentLeaveGroup(group_id: string, student_id: string, t: ComposerTranslation) { + async function studentLeaveGroup(group_id: string, student_id: string) { const endpoint = endpoints.students.byGroup.replace('{group_id}', group_id); - delete_id_with_data(endpoint, {student_id: student_id}, response, Response.fromJSON, toast, t); + await delete_id_with_data(endpoint, {student_id: student_id}, response, Response.fromJSON); } - async function createStudent(student_data: any, t: ComposerTranslation) { + async function createStudent(student_data: Student) { const endpoint = endpoints.students.index; - create(endpoint, student_data, student, Student.fromJSON, toast, t); + await create(endpoint, + { + email:student_data.email, + first_name:student_data.first_name, + last_name: student_data.last_name + }, + student, Student.fromJSON); } - async function deleteStudent(id: string, t: ComposerTranslation) { + async function deleteStudent(id: string) { const endpoint = endpoints.students.retrieve.replace('{id}', id); - delete_id(endpoint, student, Student.fromJSON, toast, t); + await delete_id(endpoint, student, Student.fromJSON); } return { diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index 4eee2bde..1145e9d8 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -2,37 +2,38 @@ import {Submission} from '@/types/Submission.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useSubmission() { const submissions = ref(null); const submission = ref(null); - const toast = useToast(); - async function getSubmissionByID(id: string, t: ComposerTranslation) { + async function getSubmissionByID(id: string) { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - get(endpoint, submission, Submission.fromJSON, toast, t); + await get(endpoint, submission, Submission.fromJSON); } - async function getSubmissionByProject(project_id: string, t: ComposerTranslation) { + async function getSubmissionByProject(project_id: string) { const endpoint = endpoints.submissions.byProject.replace('{project_id}', project_id); - getList(endpoint, submissions, Submission.fromJSON, toast, t); + await getList(endpoint, submissions, Submission.fromJSON); } - async function getSubmissionByGroup(group_id: string, t: ComposerTranslation) { + async function getSubmissionByGroup(group_id: string) { const endpoint = endpoints.submissions.byGroup.replace('{group_id}', group_id); - getList(endpoint, submissions, Submission.fromJSON, toast, t); + await getList(endpoint, submissions, Submission.fromJSON); } - async function createSubmission(submission_data: any, group_id: string, t: ComposerTranslation) { + async function createSubmission(submission_data: Submission, group_id: string) { const endpoint = endpoints.submissions.byGroup.replace('{group_id}', group_id); - create(endpoint, submission_data, submission, Submission.fromJSON, toast, t); + await create(endpoint, + { + files: submission_data.files //TODO look how this will need to be given + }, + submission, Submission.fromJSON); } - async function deleteSubmission(id: string, t: ComposerTranslation) { + async function deleteSubmission(id: string) { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - delete_id(endpoint, submission, Submission.fromJSON, toast, t); + await delete_id(endpoint, submission, Submission.fromJSON); } return { diff --git a/frontend/src/composables/services/submissionStatus.service.ts b/frontend/src/composables/services/submissionStatus.service.ts index 588c45f4..5f4bb8ab 100644 --- a/frontend/src/composables/services/submissionStatus.service.ts +++ b/frontend/src/composables/services/submissionStatus.service.ts @@ -2,16 +2,13 @@ import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get} from '@/composables/services/helpers.ts'; import { SubmissionStatus } from '@/types/SubmisionStatus'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useSubmission() { const submissionStatus = ref(null); - const toast = useToast(); - async function getSubmissionStatus(project_id: string, t: ComposerTranslation) { + async function getSubmissionStatus(project_id: string) { const endpoint = endpoints.submissions.status.replace('{project_id}', project_id); - get(endpoint, submissionStatus, SubmissionStatus.fromJSON, toast, t); + await get(endpoint, submissionStatus, SubmissionStatus.fromJSON); } return { diff --git a/frontend/src/composables/services/teachers.service.ts b/frontend/src/composables/services/teachers.service.ts index df5f5431..7d6d6e31 100644 --- a/frontend/src/composables/services/teachers.service.ts +++ b/frontend/src/composables/services/teachers.service.ts @@ -3,48 +3,51 @@ import { Response } from '@/types/Response'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import { get, getList, create, delete_id, delete_id_with_data } from '@/composables/services/helpers.ts'; -import { useToast } from 'primevue/usetoast'; -import {ComposerTranslation} from "vue-i18n"; export function useTeacher() { const teachers = ref(null); const teacher = ref(null); const response = ref(null); - const toast = useToast(); - async function getTeacherByID(id: string, t: ComposerTranslation) { + async function getTeacherByID(id: string) { const endpoint = endpoints.teachers.retrieve.replace('{id}', id); - get(endpoint, teacher, Teacher.fromJSON, toast, t); + await get(endpoint, teacher, Teacher.fromJSON); } - async function getTeacherByCourse(course_id: string, t: ComposerTranslation) { + async function getTeacherByCourse(course_id: string) { const endpoint = endpoints.teachers.byCourse.replace('{course_id}', course_id); - get(endpoint, teacher, Teacher.fromJSON, toast, t); + await get(endpoint, teacher, Teacher.fromJSON); } - async function getTeachers(t: ComposerTranslation) { + async function getTeachers() { const endpoint = endpoints.teachers.index; - getList(endpoint, teachers, Teacher.fromJSON, toast, t); + await getList(endpoint, teachers, Teacher.fromJSON); } - async function teacherJoinCourse(course_id: string, teacher_id: string, t: ComposerTranslation) { + async function teacherJoinCourse(course_id: string, teacher_id: string) { const endpoint = endpoints.teachers.byCourse.replace('{course_id}', course_id); - create(endpoint, {teacher_id: teacher_id}, response, Response.fromJSON, toast, t); + await create(endpoint, {teacher_id: teacher_id}, response, Response.fromJSON); } - async function teacherLeaveCourse(course_id: string, teacher_id: string, t: ComposerTranslation) { + async function teacherLeaveCourse(course_id: string, teacher_id: string) { const endpoint = endpoints.teachers.byCourse.replace('{course_id}', course_id); - delete_id_with_data(endpoint, {teacher_id: teacher_id}, response, Response.fromJSON, toast, t); + await delete_id_with_data(endpoint, {teacher_id: teacher_id}, response, Response.fromJSON); } - async function createTeacher(teacher_data: any, t: ComposerTranslation) { + async function createTeacher(teacher_data: Teacher) { const endpoint = endpoints.teachers.index; - create(endpoint, teacher_data, teacher, Teacher.fromJSON, toast, t); + await create(endpoint, + { + email:teacher_data.email, + first_name:teacher_data.first_name, + last_name: teacher_data.last_name + }, + teacher, Teacher.fromJSON); } - async function deleteTeacher(id: string, t: ComposerTranslation) { + async function deleteTeacher(id: string) { const endpoint = endpoints.students.retrieve.replace('{id}', id); - delete_id(endpoint, teacher, Teacher.fromJSON, toast, t); + await delete_id(endpoint, teacher, Teacher.fromJSON); } return { diff --git a/frontend/src/main.ts b/frontend/src/main.ts index dc32bb47..37de12d2 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -10,10 +10,10 @@ import {createPinia} from 'pinia'; const app = createApp(App); /* Bind application plugins */ -app.use(ToastService); - app.use(createPinia()); +app.use(ToastService); + app.use(i18n); app.use(router) diff --git a/frontend/src/test/unit/course.test.ts b/frontend/src/test/unit/course.test.ts index 9627bd5f..573b8cf9 100644 --- a/frontend/src/test/unit/course.test.ts +++ b/frontend/src/test/unit/course.test.ts @@ -9,7 +9,7 @@ describe("course", (): void => { // you can also import "test" instead of "it", because it's the exact same // but with "it", it's easy to read => it (referring to the course) returns correct course year it("returns correct course year", (): void => { - const course: Course = new Course(1, "course", "description", 2003) + const course: Course = new Course("1", "course", "description", 2003) // use expect for assertions // after expect, there are a multitude of possible functions such as: // toBe, toEqual, toContain diff --git a/frontend/src/types/User.ts b/frontend/src/types/User.ts index 1b0a1340..31de3a74 100644 --- a/frontend/src/types/User.ts +++ b/frontend/src/types/User.ts @@ -1,6 +1,6 @@ export class User { constructor( - public id: number, + public id: string, public username: string, public first_name: string, public last_name: string, diff --git a/frontend/src/views/calendar/CalendarView.vue b/frontend/src/views/calendar/CalendarView.vue index 6f6508f8..80a2392d 100644 --- a/frontend/src/views/calendar/CalendarView.vue +++ b/frontend/src/views/calendar/CalendarView.vue @@ -23,7 +23,7 @@ const { projects, getProjectsByStudent } = useProject(); // TODO: Set correct user ID const loadProjects = async () => { - await getProjectsByStudent("1", t); + await getProjectsByStudent("1"); }; /* Load the projects when the component is mounted */ diff --git a/frontend/src/views/courses/CourseView.vue b/frontend/src/views/courses/CourseView.vue index d757a613..42bb6469 100644 --- a/frontend/src/views/courses/CourseView.vue +++ b/frontend/src/views/courses/CourseView.vue @@ -1,21 +1,17 @@