diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index c2f69b82..5eedf8e4 100755 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -24,16 +24,6 @@ export default defineConfig({ // { text: 'Examples', link: '/markdown-examples' } ], - sidebar: [ - { - text: "Algemeen", - items: [ - // { text: 'Markdown Examples', link: '/markdown-examples' }, - // { text: 'Runtime API Examples', link: '/api-examples' } - ], - }, - ], - socialLinks: [ { icon: "github", link: "https://github.com/SELab-2/UGent-7" }, ], diff --git a/docs/en/index.md b/docs/en/index.md index c22a4bae..fac2f489 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -4,8 +4,7 @@ layout: home hero: name: "Ypovoli" - text: "TODO" - tagline: TODO + text: Help pagina actions: - theme: brand text: Student @@ -19,13 +18,5 @@ hero: - theme: brand text: Admin link: /en/admin-examples - -features: - - title: Feature A - details: lorem english - - title: Feature B - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit - - title: Feature C - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit --- diff --git a/docs/en/student-examples.md b/docs/en/student-examples.md index 838cc994..0e555eb3 100644 --- a/docs/en/student-examples.md +++ b/docs/en/student-examples.md @@ -93,9 +93,6 @@ This page describes how to interact with Ypovoli as a student. - Scroll to the "My Courses" section. - Click on the course of the desired project. - Under the "Current Projects" section, you will see all projects for this specific course. -- Option 4: - - Click on "Projects" in the navigation bar. - - You will see an overview of all your projects. ::: info Project card explanation ![project card](../assets/en/project-card.png) @@ -135,4 +132,4 @@ This page describes how to interact with Ypovoli as a student. ## View Previous Submissions Status - Go to the submission page. -- It says there. !!! TODO !!! +- It says there. diff --git a/docs/nl/index.md b/docs/nl/index.md index 9a981c2e..a73bf877 100644 --- a/docs/nl/index.md +++ b/docs/nl/index.md @@ -4,8 +4,7 @@ layout: home hero: name: "Ypovoli" - text: "TODO" - tagline: TODO + text: Help page actions: - theme: brand text: Student @@ -19,13 +18,5 @@ hero: - theme: brand text: Admin link: /nl/admin-examples - -features: - - title: Feature A - details: lorem nederlands - - title: Feature B - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit - - title: Feature C - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit --- diff --git a/docs/nl/student-examples.md b/docs/nl/student-examples.md index 569e2179..4695c23c 100644 --- a/docs/nl/student-examples.md +++ b/docs/nl/student-examples.md @@ -93,9 +93,6 @@ Deze pagina beschrijft hoe u als student met Ypovoli interageert. - Scrol naar de sectie "Mijn vakken". - Druk hier op het vak van het gezochte project. - Onder de sectie "Lopende projecten" ziet u alle projecten voor dit specifieke vak. -- Optie 4: - - Druk in de navigatiebalk op "Projecten". - - U ziet een overzicht van al uw projecten. ::: info Project kaart uitleg @@ -136,4 +133,4 @@ De kaart is als volgt ingedeeld: ## Status vorige indieningen bekijken - Ga naar indien pagina. -- Staat daar bij. !!! TODO !!! +- Staat daar bij. diff --git a/frontend/src/composables/services/admin.service.ts b/frontend/src/composables/services/admin.service.ts index b5e09ee7..5b576414 100644 --- a/frontend/src/composables/services/admin.service.ts +++ b/frontend/src/composables/services/admin.service.ts @@ -6,27 +6,27 @@ import { User } from '@/types/users/User.ts'; interface AdminState { admins: Ref; admin: Ref; - getAdminByID: (id: string) => Promise; - getAdmins: () => Promise; - createAdmin: (adminData: User) => Promise; - deleteAdmin: (id: string) => Promise; + getAdminByID: (id: string, selfProcessError?: boolean) => Promise; + getAdmins: (selfProcessError?: boolean) => Promise; + createAdmin: (adminData: User, selfProcessError?: boolean) => Promise; + deleteAdmin: (id: string, selfProcessError?: boolean) => Promise; } export function useAdmin(): AdminState { const admins = ref(null); const admin = ref(null); - async function getAdminByID(id: string): Promise { + async function getAdminByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - await get(endpoint, admin, User.fromJSON); + await get(endpoint, admin, User.fromJSON, selfProcessError); } - async function getAdmins(): Promise { + async function getAdmins(selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.index; - await getList(endpoint, admins, User.fromJSON); + await getList(endpoint, admins, User.fromJSON, selfProcessError); } - async function createAdmin(user: User): Promise { + async function createAdmin(user: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.index; await createToast( 'admin', @@ -36,12 +36,14 @@ export function useAdmin(): AdminState { }, admin, User.fromJSON, + undefined, + selfProcessError, ); } - async function deleteAdmin(id: string): Promise { + async function deleteAdmin(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - await deleteId(endpoint, admin, User.fromJSON); + await deleteId(endpoint, admin, User.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 98841db4..c2e5eff3 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -20,14 +20,14 @@ interface AssistantState { assistant: Ref; response: Ref; assistantPagination: Ref | null>; - getAssistantByID: (id: string, init?: boolean) => Promise; - getAssistantsByCourse: (courseId: string) => Promise; - getAssistants: () => Promise; - searchAssistants: (filters: Filter, page: number, pageSize: number) => Promise; - assistantJoinCourse: (courseId: string, assistantId: string) => Promise; - assistantLeaveCourse: (courseId: string, assistantId: string) => Promise; - createAssistant: (assistantData: Assistant) => Promise; - deleteAssistant: (id: string) => Promise; + getAssistantByID: (id: string, init?: boolean, selfProcessError?: boolean) => Promise; + getAssistantsByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getAssistants: (selfProcessError?: boolean) => Promise; + searchAssistants: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + assistantJoinCourse: (courseId: string, assistantId: string, selfProcessError?: boolean) => Promise; + assistantLeaveCourse: (courseId: string, assistantId: string, selfProcessError?: boolean) => Promise; + createAssistant: (assistantData: Assistant, selfProcessError?: boolean) => Promise; + deleteAssistant: (id: string, selfProcessError?: boolean) => Promise; } export function useAssistant(): AssistantState { @@ -37,37 +37,71 @@ export function useAssistant(): AssistantState { const response = ref(null); const assistantPagination = ref | null>(null); - async function getAssistantByID(id: string): Promise { + async function getAssistantByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.retrieve.replace('{id}', id); - await get(endpoint, assistant, Assistant.fromJSON); + await get(endpoint, assistant, Assistant.fromJSON, selfProcessError); } - async function getAssistantsByCourse(courseId: string): Promise { + async function getAssistantsByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await getList(endpoint, assistants, Assistant.fromJSON); + await getList(endpoint, assistants, Assistant.fromJSON, selfProcessError); } - async function getAssistants(): Promise { + async function getAssistants(selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.index; - await getList(endpoint, assistants, Assistant.fromJSON); + await getList(endpoint, assistants, Assistant.fromJSON, selfProcessError); } - async function searchAssistants(filters: Filter, page: number, pageSize: number): Promise { + async function searchAssistants( + filters: Filter, + page: number, + pageSize: number, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.assistants.search; - await getPaginatedList(endpoint, filters, page, pageSize, assistantPagination, Assistant.fromJSON); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + assistantPagination, + Assistant.fromJSON, + selfProcessError, + ); } - async function assistantJoinCourse(courseId: string, assistantId: string): Promise { + async function assistantJoinCourse( + courseId: string, + assistantId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await create(endpoint, { assistant: assistantId }, response, Response.fromJSON); + await create( + endpoint, + { assistant: assistantId }, + response, + Response.fromJSON, + undefined, + selfProcessError, + ); } - async function assistantLeaveCourse(courseId: string, assistantId: string): Promise { + async function assistantLeaveCourse( + courseId: string, + assistantId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { assistant: assistantId }, response, Response.fromJSON); + await deleteIdWithData( + endpoint, + { assistant: assistantId }, + response, + Response.fromJSON, + selfProcessError, + ); } - async function createAssistant(user: User): Promise { + async function createAssistant(user: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.index; await createToast( 'assistant', @@ -77,12 +111,14 @@ export function useAssistant(): AssistantState { }, assistant, Assistant.fromJSON, + undefined, + selfProcessError, ); } - async function deleteAssistant(id: string): Promise { + async function deleteAssistant(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.retrieve.replace('{id}', id); - await deleteId(endpoint, assistant, Assistant.fromJSON); + await deleteId(endpoint, assistant, Assistant.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/course.service.ts b/frontend/src/composables/services/course.service.ts index f9dad3f5..a6aa061e 100644 --- a/frontend/src/composables/services/course.service.ts +++ b/frontend/src/composables/services/course.service.ts @@ -1,30 +1,34 @@ import { Course } from '@/types/Course.ts'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { i18n } from '@/config/i18n.ts'; import { get, getList, create, patch, deleteId, getPaginatedList } from '@/composables/services/helpers.ts'; import { type Response } from '@/types/Response.ts'; import { type CoursePaginatorResponse } from '@/types/filter/Paginator.ts'; import { type Filter } from '@/types/filter/Filter.ts'; import { type User } from '@/types/users/User.ts'; -import { useMessagesStore } from '@/store/messages.store.ts'; interface CoursesState { pagination: Ref; courses: Ref; course: Ref; - getCourseByID: (id: string) => Promise; - getCourses: () => Promise; - searchCourses: (filters: Filter, page: number, pageSize: number) => Promise; - getCoursesByStudent: (studentId: string) => Promise; - getCoursesByTeacher: (teacherId: string) => Promise; - getCourseByAssistant: (assistantId: string) => Promise; - getCoursesByUser: (user: User) => Promise; - createCourse: (courseData: Course) => Promise; - updateCourse: (courseData: Course) => Promise; - cloneCourse: (courseId: string, cloneAssistants: boolean, cloneTeachers: boolean) => Promise; - activateInvitationLink: (courseId: string, linkDuration: number) => Promise; - deleteCourse: (id: string) => Promise; + + getCourseByID: (id: string, selfProcessError?: boolean) => Promise; + getCourses: (selfProcessError?: boolean) => Promise; + searchCourses: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + getCoursesByStudent: (studentId: string, selfProcessError?: boolean) => Promise; + getCoursesByTeacher: (teacherId: string, selfProcessError?: boolean) => Promise; + getCourseByAssistant: (assistantId: string, selfProcessError?: boolean) => Promise; + getCoursesByUser: (user: User, selfProcessError?: boolean) => Promise; + createCourse: (courseData: Course, selfProcessError?: boolean) => Promise; + updateCourse: (courseData: Course, selfProcessError?: boolean) => Promise; + cloneCourse: ( + courseId: string, + cloneAssistants: boolean, + cloneTeachers: boolean, + selfProcessError?: boolean, + ) => Promise; + activateInvitationLink: (courseId: string, linkDuration: number, selfProcessError?: boolean) => Promise; + deleteCourse: (id: string, selfProcessError?: boolean) => Promise; } export function useCourses(): CoursesState { @@ -33,52 +37,62 @@ export function useCourses(): CoursesState { const course = ref(null); const response = ref(null); - async function getCourseByID(id: string): Promise { + async function getCourseByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await get(endpoint, course, Course.fromJSON); + await get(endpoint, course, Course.fromJSON, selfProcessError); } - async function getCourses(): Promise { + async function getCourses(selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.index; - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } - async function searchCourses(filters: Filter, page: number, pageSize: number): Promise { + async function searchCourses( + filters: Filter, + page: number, + pageSize: number, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.courses.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, Course.fromJSON); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + pagination, + Course.fromJSON, + selfProcessError, + ); } - async function getCoursesByStudent(studentId: string): Promise { + async function getCoursesByStudent(studentId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.byStudent.replace('{studentId}', studentId); - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } - async function getCoursesByTeacher(teacherId: string): Promise { + async function getCoursesByTeacher(teacherId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.byTeacher.replace('{teacherId}', teacherId); - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } - async function getCourseByAssistant(assistantId: string): Promise { + async function getCourseByAssistant(assistantId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.byAssistant.replace('{assistantId}', assistantId); - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } - async function getCoursesByUser(user: User): Promise { + async function getCoursesByUser(user: User, selfProcessError: boolean = true): Promise { if (user.isTeacher()) { - await getCoursesByTeacher(user.id); + await getCoursesByTeacher(user.id, selfProcessError); } else if (user.isAssistant()) { - await getCourseByAssistant(user.id); + await getCourseByAssistant(user.id, selfProcessError); } else if (user.isStudent()) { - await getCoursesByStudent(user.id); + await getCoursesByStudent(user.id, selfProcessError); } else { courses.value = []; } } - async function createCourse(courseData: Course): Promise { - const { t } = i18n.global; - const { addSuccessMessage } = useMessagesStore(); - + async function createCourse(courseData: Course, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.index; await create( endpoint, @@ -93,14 +107,12 @@ export function useCourses(): CoursesState { }, course, Course.fromJSON, - ); - addSuccessMessage( - t('toasts.messages.success'), - t('toasts.messages.courses.create.success', [course.value?.name]), + undefined, + selfProcessError, ); } - async function updateCourse(courseData: Course): Promise { + async function updateCourse(courseData: Course, selfProcessError: boolean = true): Promise { // Endpoint to update is same as retrieve const endpoint = endpoints.courses.retrieve.replace('{id}', courseData.id); @@ -115,10 +127,17 @@ export function useCourses(): CoursesState { private_course: courseData.private_course, }, response, + undefined, + selfProcessError, ); } - async function cloneCourse(courseId: string, cloneAssistants: boolean, cloneTeachers: boolean): Promise { + async function cloneCourse( + courseId: string, + cloneAssistants: boolean, + cloneTeachers: boolean, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.courses.clone.replace('{courseId}', courseId); await create( endpoint, @@ -128,15 +147,21 @@ export function useCourses(): CoursesState { }, course, Course.fromJSON, + undefined, + selfProcessError, ); } - async function deleteCourse(id: string): Promise { + async function deleteCourse(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await deleteId(endpoint, course, Course.fromJSON); + await deleteId(endpoint, course, Course.fromJSON, selfProcessError); } - async function activateInvitationLink(courseId: string, linkDuration: number): Promise { + async function activateInvitationLink( + courseId: string, + linkDuration: number, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.courses.invitationLink.replace('{courseId}', courseId); await patch( endpoint, @@ -144,6 +169,8 @@ export function useCourses(): CoursesState { link_duration: linkDuration, }, response, + undefined, + selfProcessError, ); } diff --git a/frontend/src/composables/services/docker.service.ts b/frontend/src/composables/services/docker.service.ts index ba6f5d96..6ed450f2 100644 --- a/frontend/src/composables/services/docker.service.ts +++ b/frontend/src/composables/services/docker.service.ts @@ -17,12 +17,12 @@ interface DockerImagesState { pagination: Ref | null>; dockerImages: Ref; response: Ref; - getDockerImages: () => Promise; - searchDockerImages: (filters: Filter, page: number, pageSize: number) => Promise; - patchDockerImage: (dockerData: DockerImage) => Promise; - createDockerImage: (dockerData: DockerImage, file: File) => Promise; - deleteDockerImage: (id: string) => Promise; - deleteDockerImages: (ids: string[]) => Promise; + getDockerImages: (selfProcessError?: boolean) => Promise; + searchDockerImages: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + patchDockerImage: (dockerData: DockerImage, selfProcessError?: boolean) => Promise; + createDockerImage: (dockerData: DockerImage, file: File, selfProcessError?: boolean) => Promise; + deleteDockerImage: (id: string, selfProcessError?: boolean) => Promise; + deleteDockerImages: (ids: string[], selfProcessError?: boolean) => Promise; } export function useDockerImages(): DockerImagesState { @@ -30,22 +30,39 @@ export function useDockerImages(): DockerImagesState { const dockerImages = ref(null); const response = ref(null); - async function getDockerImages(): Promise { + async function getDockerImages(selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.index; - await getList(endpoint, dockerImages, DockerImage.fromJSON); + await getList(endpoint, dockerImages, DockerImage.fromJSON, selfProcessError); } - async function searchDockerImages(filters: Filter, page: number, pageSize: number): Promise { + async function searchDockerImages( + filters: Filter, + page: number, + pageSize: number, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.dockerImages.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, DockerImage.fromJSON); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + pagination, + DockerImage.fromJSON, + selfProcessError, + ); } - async function patchDockerImage(dockerData: DockerImage): Promise { + async function patchDockerImage(dockerData: DockerImage, selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.patch.replace('{id}', dockerData.id); - await patch(endpoint, { public: dockerData.public }, response); + await patch(endpoint, { public: dockerData.public }, response, undefined, selfProcessError); } - async function createDockerImage(dockerData: DockerImage, file: File): Promise { + async function createDockerImage( + dockerData: DockerImage, + file: File, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.dockerImages.index; await createToast( 'docker', @@ -58,18 +75,19 @@ export function useDockerImages(): DockerImagesState { response, Response.fromJSON, 'multipart/form-data', + selfProcessError, ); } - async function deleteDockerImage(id: string): Promise { + async function deleteDockerImage(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.retrieve.replace('{id}', id); - await deleteId(endpoint, response, Response.fromJSON); + await deleteId(endpoint, response, Response.fromJSON, selfProcessError); } - async function deleteDockerImages(ids: string[]): Promise { + async function deleteDockerImages(ids: string[], selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.deleteMany; const data = { ids }; - await deleteIdWithData(endpoint, data, response, Response.fromJSON); + await deleteIdWithData(endpoint, data, response, Response.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/extra_checks.service.ts b/frontend/src/composables/services/extra_checks.service.ts index 4f94fec7..1e7a99f1 100644 --- a/frontend/src/composables/services/extra_checks.service.ts +++ b/frontend/src/composables/services/extra_checks.service.ts @@ -7,10 +7,10 @@ import { Response } from '@/types/Response'; interface ExtraCheckState { extraCheck: Ref; extraChecks: Ref; - getExtraChecksByProject: (projectId: string) => Promise; - addExtraCheck: (extraCheckData: ExtraCheck, projectId: string) => Promise; - setExtraChecks: (extraChecks: ExtraCheck[], projectId: string) => Promise; - deleteExtraCheck: (extraCheckId: string) => Promise; + getExtraChecksByProject: (projectId: string, selfProcessError?: boolean) => Promise; + addExtraCheck: (extraCheckData: ExtraCheck, projectId: string, selfProcessError?: boolean) => Promise; + setExtraChecks: (extraChecks: ExtraCheck[], projectId: string, selfProcessError?: boolean) => Promise; + deleteExtraCheck: (extraCheckId: string, selfProcessError?: boolean) => Promise; } export function useExtraCheck(): ExtraCheckState { @@ -18,12 +18,16 @@ export function useExtraCheck(): ExtraCheckState { const extraChecks = ref(null); const response = ref(null); - async function getExtraChecksByProject(projectId: string): Promise { + async function getExtraChecksByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId); - await getList(endpoint, extraChecks, ExtraCheck.fromJSON); + await getList(endpoint, extraChecks, ExtraCheck.fromJSON, selfProcessError); } - async function addExtraCheck(extraCheckData: ExtraCheck, projectId: string): Promise { + async function addExtraCheck( + extraCheckData: ExtraCheck, + projectId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -38,20 +42,25 @@ export function useExtraCheck(): ExtraCheckState { extraCheck, ExtraCheck.fromJSON, 'multipart/form-data', + selfProcessError, ); } - async function setExtraChecks(extraChecks: ExtraCheck[], projectId: string): Promise { + async function setExtraChecks( + extraChecks: ExtraCheck[], + projectId: string, + selfProcessError: boolean = true, + ): Promise { for (const extraCheck of extraChecks) { if (extraCheck.id === '') { - await addExtraCheck(extraCheck, projectId); + await addExtraCheck(extraCheck, projectId, selfProcessError); } } } - async function deleteExtraCheck(extraCheckId: string): Promise { + async function deleteExtraCheck(extraCheckId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.extraChecks.retrieve.replace('{id}', extraCheckId); - await deleteId(endpoint, response, Response.fromJSON); + await deleteId(endpoint, response, Response.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/faculty.service.ts b/frontend/src/composables/services/faculty.service.ts index 8d9dfce4..6c2c31f4 100644 --- a/frontend/src/composables/services/faculty.service.ts +++ b/frontend/src/composables/services/faculty.service.ts @@ -6,27 +6,27 @@ import { get, getList, deleteId, createToast } from '@/composables/services/help interface FacultyState { faculties: Ref; faculty: Ref; - getFacultyByID: (id: string) => Promise; - getFaculties: () => Promise; - createFaculty: (facultyData: Faculty) => Promise; - deleteFaculty: (id: string) => Promise; + getFacultyByID: (id: string, selfProcessError?: boolean) => Promise; + getFaculties: (selfProcessError?: boolean) => Promise; + createFaculty: (facultyData: Faculty, selfProcessError?: boolean) => Promise; + deleteFaculty: (id: string, selfProcessError?: boolean) => Promise; } export function useFaculty(): FacultyState { const faculties = ref(null); const faculty = ref(null); - async function getFacultyByID(id: string): Promise { + async function getFacultyByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.retrieve.replace('{id}', id); - await get(endpoint, faculty, Faculty.fromJSON); + await get(endpoint, faculty, Faculty.fromJSON, selfProcessError); } - async function getFaculties(): Promise { + async function getFaculties(selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.index; - await getList(endpoint, faculties, Faculty.fromJSON); + await getList(endpoint, faculties, Faculty.fromJSON, selfProcessError); } - async function createFaculty(facultyData: Faculty): Promise { + async function createFaculty(facultyData: Faculty, selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.index; await createToast( 'faculty', @@ -34,12 +34,14 @@ export function useFaculty(): FacultyState { { id: facultyData.id, name: facultyData.name }, faculty, Faculty.fromJSON, + undefined, + selfProcessError, ); } - async function deleteFaculty(id: string): Promise { + async function deleteFaculty(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.retrieve.replace('{id}', id); - await deleteId(endpoint, faculty, Faculty.fromJSON); + await deleteId(endpoint, faculty, Faculty.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/group.service.ts b/frontend/src/composables/services/group.service.ts index 943118b7..cf212cff 100644 --- a/frontend/src/composables/services/group.service.ts +++ b/frontend/src/composables/services/group.service.ts @@ -7,13 +7,13 @@ import type { Response } from '@/types/Response.ts'; interface GroupState { groups: Ref; group: Ref; - getGroupByID: (id: string) => Promise; - getGroupsByProject: (projectId: string) => Promise; - getGroupsByStudent: (studentId: string) => Promise; - getGroupByStudentProject: (projectId: string) => Promise; - createGroup: (groupData: Group, projectId: string) => Promise; - updateGroup: (groupData: Partial) => Promise; - deleteGroup: (id: string) => Promise; + getGroupByID: (id: string, selfProcessError?: boolean) => Promise; + getGroupsByProject: (projectId: string, selfProcessError?: boolean) => Promise; + getGroupsByStudent: (studentId: string, selfProcessError?: boolean) => Promise; + getGroupByStudentProject: (projectId: string, selfProcessError?: boolean) => Promise; + createGroup: (groupData: Group, projectId: string, selfProcessError?: boolean) => Promise; + updateGroup: (groupData: Partial, selfProcessError?: boolean) => Promise; + deleteGroup: (id: string, selfProcessError?: boolean) => Promise; } export function useGroup(): GroupState { @@ -21,27 +21,27 @@ export function useGroup(): GroupState { const group = ref(null); const response = ref(null); - async function getGroupByID(id: string): Promise { + async function getGroupByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - await get(endpoint, group, Group.fromJSON); + await get(endpoint, group, Group.fromJSON, selfProcessError); } - async function getGroupsByProject(projectId: string): Promise { + async function getGroupsByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.byProject.replace('{projectId}', projectId); - await getList(endpoint, groups, Group.fromJSON); + await getList(endpoint, groups, Group.fromJSON, selfProcessError); } - async function getGroupsByStudent(studentId: string): Promise { + async function getGroupsByStudent(studentId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.byStudent.replace('{studentId}', studentId); - await getList(endpoint, groups, Group.fromJSON); + await getList(endpoint, groups, Group.fromJSON, selfProcessError); } - async function getGroupByStudentProject(projectId: string): Promise { + async function getGroupByStudentProject(projectId: string, selfProcessError: boolean = false): Promise { const endpoint = endpoints.groups.byProjectStudent.replace('{projectId}', projectId); - await get(endpoint, group, Group.fromJSON); + await get(endpoint, group, Group.fromJSON, selfProcessError); } - async function createGroup(groupData: Group, projectId: string): Promise { + async function createGroup(groupData: Group, projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -51,10 +51,12 @@ export function useGroup(): GroupState { }, group, Group.fromJSON, + undefined, + selfProcessError, ); } - async function updateGroup(groupData: Partial): Promise { + async function updateGroup(groupData: Partial, selfProcessError: boolean = false): Promise { if (groupData.id !== undefined) { const endpoint = endpoints.groups.retrieve.replace('{id}', groupData.id); await patch( @@ -63,13 +65,14 @@ export function useGroup(): GroupState { score: groupData.score, }, response, + selfProcessError, ); } } - async function deleteGroup(id: string): Promise { + async function deleteGroup(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - await deleteId(endpoint, group, Group.fromJSON); + await deleteId(endpoint, group, Group.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index a5ff033f..4eab55c7 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -14,7 +14,12 @@ import { type Filter } from '@/types/filter/Filter.ts'; * @param ref * @param fromJson */ -export async function get(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { +export async function get( + endpoint: string, + ref: Ref, + fromJson: (data: any) => T, + selfProcessError: boolean = true, +): Promise { try { const response = await client.get(endpoint); @@ -22,9 +27,12 @@ export async function get(endpoint: string, ref: Ref, fromJson: (da ref.value = fromJson(response.data); } } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } } } @@ -43,6 +51,7 @@ export async function create( ref: Ref, fromJson: (data: any) => T, contentType: string = 'application/json', + selfProcessError: boolean = true, ): Promise { try { const response = await client.post(endpoint, data, { @@ -52,9 +61,12 @@ export async function create( }); ref.value = fromJson(response.data); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } } } @@ -96,6 +108,7 @@ export async function patch( data: any, ref: Ref, contentType: string = 'application/json', + selfProcessError: boolean = true, ): Promise { try { const response: AxiosResponse = await client.patch(endpoint, data, { @@ -105,9 +118,12 @@ export async function patch( }); ref.value = Response.fromJSON(response.data); } catch (error: any) { - processError(error); - console.error(error); - throw error; + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } } } @@ -122,12 +138,22 @@ export async function put( endpoint: string, data: T | string, contentType: string = 'application/json', + selfProcessError: boolean = true, ): Promise { - await client.put(endpoint, data, { - headers: { - 'Content-Type': contentType, - }, - }); + try { + await client.put(endpoint, data, { + headers: { + 'Content-Type': contentType, + }, + }); + } catch (error: any) { + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } + } } /** @@ -137,14 +163,22 @@ export async function put( * @param ref * @param fromJson */ -export async function deleteId(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { +export async function deleteId( + endpoint: string, + ref: Ref, + fromJson: (data: any) => T, + selfProcessError: boolean = true, +): Promise { try { const response = await client.delete(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } } } @@ -161,14 +195,18 @@ export async function deleteIdWithData( data: any, ref: Ref, fromJson: (data: any) => T, + selfProcessError: boolean = true, ): Promise { try { const response = await client.delete(endpoint, { data }); ref.value = fromJson(response.data); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } } } @@ -179,15 +217,23 @@ export async function deleteIdWithData( * @param ref * @param fromJson */ -export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { +export async function getList( + endpoint: string, + ref: Ref, + fromJson: (data: any) => T, + selfProcessError: boolean = true, +): Promise { try { const response = await client.get(endpoint); ref.value = response.data.map((data: T) => fromJson(data)); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging ref.value = []; // Set the ref to an empty array - throw error; // Re-throw the error to the caller + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } } } @@ -208,6 +254,7 @@ export async function getPaginatedList( pageSize: number, pagination: Ref | null>, fromJson: (data: any) => T, + selfProcessError: boolean = true, ): Promise { try { const response = await client.get(endpoint, { @@ -223,9 +270,6 @@ export async function getPaginatedList( results: response.data.results.map((data: T) => fromJson(data)), }; } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - pagination.value = { // Set the ref to an empty array ...error.data, @@ -233,7 +277,12 @@ export async function getPaginatedList( results: [], }; - throw error; // Re-throw the error to the caller + if (selfProcessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } } } diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index dd045d52..05e2f713 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -1,24 +1,28 @@ -import { Project, type ProjectJSON } from '@/types/Project'; +import { Project } from '@/types/Project'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; import { i18n } from '@/config/i18n.ts'; -import axios from 'axios'; -import { create, deleteId, get, getList, patch, processError } from '@/composables/services/helpers.ts'; +import { create, deleteId, get, getList, patch } from '@/composables/services/helpers.ts'; import { type Response } from '@/types/Response.ts'; import { useMessagesStore } from '@/store/messages.store.ts'; interface ProjectState { projects: Ref; project: Ref; - getProjectByID: (id: string) => Promise; - getProjectsByCourse: (courseId: string) => Promise; - getProjectsByStudent: (studentId: string) => Promise; - getProjectsByAssistant: (assistantId: string) => Promise; - getProjectsByTeacher: (teacherId: string) => Promise; - getProjectsByCourseAndDeadline: (courseId: string, deadlineDate: Date) => Promise; - createProject: (projectData: Project, courseId: string, numberOfGroups: number) => Promise; - updateProject: (projectData: Project) => Promise; - deleteProject: (id: string) => Promise; + getProjectByID: (id: string, selfProcessError?: boolean) => Promise; + getProjectsByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getProjectsByStudent: (studentId: string, selfProcessError?: boolean) => Promise; + getProjectsByAssistant: (assistantId: string, selfProcessError?: boolean) => Promise; + getProjectsByTeacher: (teacherId: string, selfProcessError?: boolean) => Promise; + getProjectsByCourseAndDeadline: (courseId: string, deadlineDate: Date, selfProcessError?: boolean) => Promise; + createProject: ( + projectData: Project, + courseId: string, + numberOfGroups: number, + selfProcessError?: boolean, + ) => Promise; + updateProject: (projectData: Project, selfProcessError?: boolean) => Promise; + deleteProject: (id: string, selfProcessError?: boolean) => Promise; } export function useProject(): ProjectState { @@ -26,56 +30,51 @@ export function useProject(): ProjectState { const project = ref(null); const response = ref(null); - async function getProjectByID(id: string): Promise { + async function getProjectByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', id); - await get(endpoint, project, Project.fromJSON); + await get(endpoint, project, Project.fromJSON, selfProcessError); } - async function getProjectsByCourse(courseId: string): Promise { + async function getProjectsByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } - async function getProjectsByStudent(studentId: string): Promise { + async function getProjectsByStudent(studentId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byStudent.replace('{studentId}', studentId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } - async function getProjectsByAssistant(assistantId: string): Promise { + async function getProjectsByAssistant(assistantId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byAssistant.replace('{assistantId}', assistantId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } - async function getProjectsByTeacher(teacherId: string): Promise { + async function getProjectsByTeacher(teacherId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byTeacher.replace('{teacherId}', teacherId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } - async function getProjectsByCourseAndDeadline(courseId: string, deadlineDate: Date): Promise { - const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); + async function getProjectsByCourseAndDeadline( + courseId: string, + deadlineDate: Date, + selfProcessError: boolean = true, + ): Promise { + await getProjectsByCourse(courseId, selfProcessError); - await axios - .get(endpoint) - .then((response) => { - const allProjects = response.data.map((projectData: ProjectJSON) => Project.fromJSON(projectData)); - - // Filter projects based on the deadline date - // Update the projects ref with the filtered projects - projects.value = allProjects.filter((project: Project) => { - return project.deadline.toDateString() === deadlineDate.toDateString(); - }); - }) - .catch((error) => { - if (axios.isAxiosError(error)) { - processError(error); - console.log(error.response?.data); - } else { - console.error('An unexpected error ocurred: ', error); - } + if (projects.value !== null) { + projects.value = projects.value.filter((project: Project) => { + return project.deadline.toDateString() === deadlineDate.toDateString(); }); + } } - async function createProject(projectData: Project, courseId: string, numberOfGroups: number): Promise { + async function createProject( + projectData: Project, + courseId: string, + numberOfGroups: number, + selfProcessError: boolean = true, + ): Promise { const { t } = i18n.global; const { addSuccessMessage } = useMessagesStore(); @@ -100,14 +99,21 @@ export function useProject(): ProjectState { requestData.number_groups = numberOfGroups; } - await create(endpoint, requestData, project, Project.fromJSON, 'multipart/form-data'); + await create( + endpoint, + requestData, + project, + Project.fromJSON, + 'multipart/form-data', + selfProcessError, + ); addSuccessMessage( t('toasts.messages.success'), t('toasts.messages.projects.create.success', [project.value?.name]), ); } - async function updateProject(projectData: Project): Promise { + async function updateProject(projectData: Project, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', projectData.id); await patch( endpoint, @@ -125,12 +131,13 @@ export function useProject(): ProjectState { }, response, 'multipart/form-data', + selfProcessError, ); } - async function deleteProject(id: string): Promise { + async function deleteProject(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', id); - await deleteId(endpoint, project, Project.fromJSON); + await deleteId(endpoint, project, Project.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index 405cb07c..fa1df7fe 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -6,28 +6,41 @@ import { get, getList, createToast, deleteId, put } from '@/composables/services interface StructureCheckState { structureChecks: Ref; structureCheck: Ref; - getStructureCheckByID: (id: string) => Promise; - getStructureCheckByProject: (projectId: string) => Promise; - createStructureCheck: (structureCheckData: StructureCheck, projectId: string) => Promise; - setStructureChecks: (structureChecks: StructureCheck[], projectId: string) => Promise; - deleteStructureCheck: (id: string) => Promise; + + getStructureCheckByID: (id: string, selfProcessError?: boolean) => Promise; + getStructureCheckByProject: (projectId: string, selfProcessError?: boolean) => Promise; + createStructureCheck: ( + structureCheckData: StructureCheck, + projectId: string, + selfProcessError?: boolean, + ) => Promise; + setStructureChecks: ( + structureChecks: StructureCheck[], + projectId: string, + selfProcessError?: boolean, + ) => Promise; + deleteStructureCheck: (id: string, selfProcessError?: boolean) => Promise; } export function useStructureCheck(): StructureCheckState { const structureChecks = ref(null); const structureCheck = ref(null); - async function getStructureCheckByID(id: string): Promise { + async function getStructureCheckByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.retrieve.replace('{id}', id); - await get(endpoint, structureCheck, StructureCheck.fromJSON); + await get(endpoint, structureCheck, StructureCheck.fromJSON, selfProcessError); } - async function getStructureCheckByProject(projectId: string): Promise { + async function getStructureCheckByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); - await getList(endpoint, structureChecks, StructureCheck.fromJSON); + await getList(endpoint, structureChecks, StructureCheck.fromJSON, selfProcessError); } - async function createStructureCheck(structureCheckData: StructureCheck, projectId: string): Promise { + async function createStructureCheck( + structureCheckData: StructureCheck, + projectId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); await createToast( 'structureCheck', @@ -37,17 +50,23 @@ export function useStructureCheck(): StructureCheckState { }, structureCheck, StructureCheck.fromJSON, + undefined, + selfProcessError, ); } - async function setStructureChecks(structureChecks: StructureCheck[], projectId: string): Promise { + async function setStructureChecks( + structureChecks: StructureCheck[], + projectId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); - await put(endpoint, structureChecks); + await put(endpoint, structureChecks, undefined, selfProcessError); } - async function deleteStructureCheck(id: string): Promise { + async function deleteStructureCheck(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.retrieve.replace('{id}', id); - await deleteId(endpoint, structureCheck, StructureCheck.fromJSON); + await deleteId(endpoint, structureCheck, StructureCheck.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index 713ac8d3..f12cf6d6 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -8,16 +8,16 @@ interface StudentsState { students: Ref; student: Ref; response: Ref; - getStudentByID: (id: string, init?: boolean) => Promise; - getStudents: () => Promise; - getStudentsByCourse: (courseId: string) => Promise; - getStudentsByGroup: (groupId: string) => Promise; - createStudent: (studentData: Student) => Promise; - deleteStudent: (id: string) => Promise; - studentJoinCourse: (courseId: string, studentId: string) => Promise; - studentLeaveCourse: (courseId: string, studentId: string) => Promise; - studentJoinGroup: (groupId: string, studentId: string) => Promise; - studentLeaveGroup: (groupId: string, studentId: string) => Promise; + getStudentByID: (id: string, init?: boolean, selfProcessError?: boolean) => Promise; + getStudents: (selfProcessError?: boolean) => Promise; + getStudentsByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getStudentsByGroup: (groupId: string, selfProcessError?: boolean) => Promise; + createStudent: (studentData: Student, selfProcessError?: boolean) => Promise; + deleteStudent: (id: string, selfProcessError?: boolean) => Promise; + studentJoinCourse: (courseId: string, studentId: string, selfProcessError?: boolean) => Promise; + studentLeaveCourse: (courseId: string, studentId: string, selfProcessError?: boolean) => Promise; + studentJoinGroup: (groupId: string, studentId: string, selfProcessError?: boolean) => Promise; + studentLeaveGroup: (groupId: string, studentId: string, selfProcessError?: boolean) => Promise; } export function useStudents(): StudentsState { @@ -26,47 +26,89 @@ export function useStudents(): StudentsState { const student = ref(null); const response = ref(null); - async function getStudentByID(id: string): Promise { + async function getStudentByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.retrieve.replace('{id}', id); - await get(endpoint, student, Student.fromJSON); + await get(endpoint, student, Student.fromJSON, selfProcessError); } - async function getStudents(): Promise { + async function getStudents(selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.index; - await getList(endpoint, students, Student.fromJSON); + await getList(endpoint, students, Student.fromJSON, selfProcessError); } - async function getStudentsByCourse(courseId: string): Promise { + async function getStudentsByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await getList(endpoint, students, Student.fromJSON); + await getList(endpoint, students, Student.fromJSON, selfProcessError); } - async function getStudentsByGroup(groupId: string): Promise { + async function getStudentsByGroup(groupId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await getList(endpoint, students, Student.fromJSON); + await getList(endpoint, students, Student.fromJSON, selfProcessError); } - async function studentJoinCourse(courseId: string, studentId: string): Promise { + async function studentJoinCourse( + courseId: string, + studentId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await create(endpoint, { student: studentId }, response, Response.fromJSON); + await create( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + undefined, + selfProcessError, + ); } - async function studentLeaveCourse(courseId: string, studentId: string): Promise { + async function studentLeaveCourse( + courseId: string, + studentId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON); + await deleteIdWithData( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + selfProcessError, + ); } - async function studentJoinGroup(groupId: string, studentId: string): Promise { + async function studentJoinGroup( + groupId: string, + studentId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await create(endpoint, { student: studentId }, response, Response.fromJSON); + await create( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + undefined, + selfProcessError, + ); } - async function studentLeaveGroup(groupId: string, studentId: string): Promise { + async function studentLeaveGroup( + groupId: string, + studentId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON); + await deleteIdWithData( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + selfProcessError, + ); } - async function createStudent(studentData: Student): Promise { + async function createStudent(studentData: Student, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.index; await createToast( @@ -78,12 +120,14 @@ export function useStudents(): StudentsState { }, student, Student.fromJSON, + undefined, + selfProcessError, ); } - async function deleteStudent(id: string): Promise { + async function deleteStudent(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.retrieve.replace('{id}', id); - await deleteId(endpoint, student, Student.fromJSON); + await deleteId(endpoint, student, Student.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index 261598c9..2387d0a2 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -8,33 +8,37 @@ import { useMessagesStore } from '@/store/messages.store.ts'; interface SubmissionState { submissions: Ref; submission: Ref; - getSubmissionByID: (id: string) => Promise; - getSubmissionByProject: (projectId: string) => Promise; - getSubmissionByGroup: (groupId: string) => Promise; - createSubmission: (submissionData: UnwrapRef, groupId: string) => Promise; - deleteSubmission: (id: string) => Promise; + getSubmissionByID: (id: string, selfProcessError?: boolean) => Promise; + getSubmissionByProject: (projectId: string, selfProcessError?: boolean) => Promise; + getSubmissionByGroup: (groupId: string, selfProcessError?: boolean) => Promise; + createSubmission: (submissionData: UnwrapRef, groupId: string, selfProcessError?: boolean) => Promise; + deleteSubmission: (id: string, selfProcessError?: boolean) => Promise; } export function useSubmission(): SubmissionState { const submissions = ref(null); const submission = ref(null); - async function getSubmissionByID(id: string): Promise { + async function getSubmissionByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - await get(endpoint, submission, Submission.fromJSON); + await get(endpoint, submission, Submission.fromJSON, selfProcessError); } - async function getSubmissionByProject(projectId: string): Promise { + async function getSubmissionByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.byProject.replace('{projectId}', projectId); - await getList(endpoint, submissions, Submission.fromJSON); + await getList(endpoint, submissions, Submission.fromJSON, selfProcessError); } - async function getSubmissionByGroup(groupId: string): Promise { + async function getSubmissionByGroup(groupId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.byGroup.replace('{groupId}', groupId); - await getList(endpoint, submissions, Submission.fromJSON); + await getList(endpoint, submissions, Submission.fromJSON, selfProcessError); } - async function createSubmission(uploadedFiles: File[], groupId: string): Promise { + async function createSubmission( + uploadedFiles: File[], + groupId: string, + selfProcessError: boolean = true, + ): Promise { const { t } = i18n.global; const { addSuccessMessage } = useMessagesStore(); @@ -44,14 +48,13 @@ export function useSubmission(): SubmissionState { uploadedFiles.forEach((file: File) => { formData.append('files', file); // Gebruik 'files' in plaats van 'files[]' }); - - await create(endpoint, formData, submission, Submission.fromJSON, 'multipart/form-data'); + await create(endpoint, formData, submission, Submission.fromJSON, 'multipart/form-data', selfProcessError); addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.submissions.create.success')); } - async function deleteSubmission(id: string): Promise { + async function deleteSubmission(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - await deleteId(endpoint, submission, Submission.fromJSON); + await deleteId(endpoint, submission, Submission.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/submission_status.service.ts b/frontend/src/composables/services/submission_status.service.ts index 77174b7a..e63cb176 100644 --- a/frontend/src/composables/services/submission_status.service.ts +++ b/frontend/src/composables/services/submission_status.service.ts @@ -5,15 +5,15 @@ import { SubmissionStatus } from '@/types/SubmisionStatus'; interface SubmissionStatusState { submissionStatus: Ref; - getSubmissionStatusByProject: (projectId: string) => Promise; + getSubmissionStatusByProject: (projectId: string, selfProcessError?: boolean) => Promise; } export function useSubmissionStatus(): SubmissionStatusState { const submissionStatus = ref(null); - async function getSubmissionStatusByProject(projectId: string): Promise { + async function getSubmissionStatusByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.status.replace('{projectId}', projectId); - await get(endpoint, submissionStatus, SubmissionStatus.fromJSON); + await get(endpoint, submissionStatus, SubmissionStatus.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 708ca51c..f25583c5 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -21,14 +21,14 @@ interface TeacherState { teacher: Ref; response: Ref; teacherPagination: Ref | null>; - getTeacherByID: (id: string, init?: boolean) => Promise; - getTeachersByCourse: (courseId: string) => Promise; - getTeachers: () => Promise; - searchTeachers: (filters: Filter, page: number, pageSize: number) => Promise; - teacherJoinCourse: (courseId: string, teacherId: string) => Promise; - teacherLeaveCourse: (courseId: string, teacherId: string) => Promise; - createTeacher: (teacherData: Teacher) => Promise; - deleteTeacher: (id: string) => Promise; + getTeacherByID: (id: string, init?: boolean, selfProcessError?: boolean) => Promise; + getTeachersByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getTeachers: (selfProcessError?: boolean) => Promise; + searchTeachers: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + teacherJoinCourse: (courseId: string, teacherId: string, selfProcessError?: boolean) => Promise; + teacherLeaveCourse: (courseId: string, teacherId: string, selfProcessError?: boolean) => Promise; + createTeacher: (teacherData: Teacher, selfProcessError?: boolean) => Promise; + deleteTeacher: (id: string, selfProcessError?: boolean) => Promise; } export function useTeacher(): TeacherState { @@ -38,37 +38,71 @@ export function useTeacher(): TeacherState { const response = ref(null); const teacherPagination = ref | null>(null); - async function getTeacherByID(id: string): Promise { + async function getTeacherByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.retrieve.replace('{id}', id); - await get(endpoint, teacher, Teacher.fromJSON); + await get(endpoint, teacher, Teacher.fromJSON, selfProcessError); } - async function getTeachersByCourse(courseId: string): Promise { + async function getTeachersByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await getList(endpoint, teachers, Teacher.fromJSON); + await getList(endpoint, teachers, Teacher.fromJSON, selfProcessError); } - async function getTeachers(): Promise { + async function getTeachers(selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.index; - await getList(endpoint, teachers, Teacher.fromJSON); + await getList(endpoint, teachers, Teacher.fromJSON, selfProcessError); } - async function searchTeachers(filters: Filter, page: number, pageSize: number): Promise { + async function searchTeachers( + filters: Filter, + page: number, + pageSize: number, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.teachers.search; - await getPaginatedList(endpoint, filters, page, pageSize, teacherPagination, Teacher.fromJSON); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + teacherPagination, + Teacher.fromJSON, + selfProcessError, + ); } - async function teacherJoinCourse(courseId: string, teacherId: string): Promise { + async function teacherJoinCourse( + courseId: string, + teacherId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await create(endpoint, { teacher: teacherId }, response, Response.fromJSON); + await create( + endpoint, + { teacher: teacherId }, + response, + Response.fromJSON, + undefined, + selfProcessError, + ); } - async function teacherLeaveCourse(courseId: string, teacherId: string): Promise { + async function teacherLeaveCourse( + courseId: string, + teacherId: string, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { teacher: teacherId }, response, Response.fromJSON); + await deleteIdWithData( + endpoint, + { teacher: teacherId }, + response, + Response.fromJSON, + selfProcessError, + ); } - async function createTeacher(user: User): Promise { + async function createTeacher(user: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.index; await createToast( 'teacher', @@ -78,12 +112,14 @@ export function useTeacher(): TeacherState { }, teacher, Teacher.fromJSON, + undefined, + selfProcessError, ); } - async function deleteTeacher(id: string): Promise { + async function deleteTeacher(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.retrieve.replace('{id}', id); - await deleteId(endpoint, teacher, Teacher.fromJSON); + await deleteId(endpoint, teacher, Teacher.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/users.service.ts b/frontend/src/composables/services/users.service.ts index 565e5967..1f6bfaf9 100644 --- a/frontend/src/composables/services/users.service.ts +++ b/frontend/src/composables/services/users.service.ts @@ -10,11 +10,11 @@ interface userState { pagination: Ref | null>; users: Ref; user: Ref; - getUserByID: (id: string) => Promise; - getUsers: () => Promise; - searchUsers: (filters: Filter, page: number, pageSize: number) => Promise; - createUser: (user_data: User) => Promise; - toggleAdmin: (id: string, is_staff: boolean) => Promise; + getUserByID: (id: string, selfProcessError?: boolean) => Promise; + getUsers: (selfProcessError?: boolean) => Promise; + searchUsers: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + createUser: (user_data: User, selfProcessError?: boolean) => Promise; + toggleAdmin: (id: string, is_staff: boolean, selfProcessError?: boolean) => Promise; } export function useUser(): userState { @@ -23,22 +23,27 @@ export function useUser(): userState { const user = ref(null); const response = ref(null); - async function getUserByID(id: string): Promise { + async function getUserByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.retrieve.replace('{id}', id); - await get(endpoint, user, User.fromJSON); + await get(endpoint, user, User.fromJSON, selfProcessError); } - async function getUsers(): Promise { + async function getUsers(selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.index; - await getList(endpoint, users, User.fromJSON); + await getList(endpoint, users, User.fromJSON, selfProcessError); } - async function searchUsers(filters: Filter, page: number, pageSize: number): Promise { + async function searchUsers( + filters: Filter, + page: number, + pageSize: number, + selfProcessError: boolean = true, + ): Promise { const endpoint = endpoints.users.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON); + await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON, selfProcessError); } - async function createUser(userData: User): Promise { + async function createUser(userData: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.index; await createToast( 'user', @@ -52,10 +57,12 @@ export function useUser(): userState { }, user, User.fromJSON, + undefined, + selfProcessError, ); } - async function toggleAdmin(id: string, isStaff: boolean): Promise { + async function toggleAdmin(id: string, isStaff: boolean, selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.admin.replace('{id}', id); await patch( endpoint, @@ -63,6 +70,8 @@ export function useUser(): userState { is_staff: isStaff, }, response, + undefined, + selfProcessError, ); } diff --git a/frontend/src/views/courses/CreateCourseView.vue b/frontend/src/views/courses/CreateCourseView.vue index 20cf69e4..d78b3e9c 100644 --- a/frontend/src/views/courses/CreateCourseView.vue +++ b/frontend/src/views/courses/CreateCourseView.vue @@ -9,9 +9,11 @@ import { useFaculty } from '@/composables/services/faculty.service.ts'; import { type Course } from '@/types/Course.ts'; import { useCourses } from '@/composables/services/course.service.ts'; import { useRouter } from 'vue-router'; +import { useMessagesStore } from '@/store/messages.store.ts'; /* Composable injections */ const { t } = useI18n(); +const { addSuccessMessage } = useMessagesStore(); const { push } = useRouter(); const { faculties, getFaculties } = useFaculty(); const { createCourse } = useCourses(); @@ -25,8 +27,13 @@ const loading = ref(true); * @param course */ async function saveCourse(course: Course): Promise { - await createCourse(course); - await push({ name: 'dashboard' }); + try { + await createCourse(course); + addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.courses.create.success', [course.name])); + await push({ name: 'dashboard' }); + } catch (error: any) { + // TODO error message + } } /** Load the data */