diff --git a/frontend/src/composables/services/admins.service.ts b/frontend/src/composables/services/admins.service.ts index 8cb75e4c..8ec88562 100644 --- a/frontend/src/composables/services/admins.service.ts +++ b/frontend/src/composables/services/admins.service.ts @@ -1,7 +1,7 @@ import {Admin} from '@/types/Admin.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useAdmin() { @@ -9,22 +9,34 @@ export function useAdmin() { const admin = ref(null); const toast = useToast(); - async function getAdminByID(id: number) { - const endpoint = endpoints.admins.retrieve.replace('{id}', id.toString()); + async function getAdminByID(id: string) { + const endpoint = endpoints.admins.retrieve.replace('{id}', id); get(endpoint, admin, Admin.fromJSON, toast); - console.log(admin) } async function getAdmins() { const endpoint = endpoints.admins.index; getList(endpoint, admins, Admin.fromJSON, toast); - console.log(admins.value ? admins.value.map((admin, index) => `Admin ${index + 1}: ${JSON.stringify(admin)}`) : 'Admins is null'); + } + + + async function createAdmin(admin_data: any) { + const endpoint = endpoints.admins.index; + create(endpoint, admin_data, admin, Admin.fromJSON, toast); + } + + async function deleteAdmin(id: string) { + const endpoint = endpoints.admins.retrieve.replace('{id}', id.toString()); + delete_id(endpoint, admin, Admin.fromJSON, toast); } return { admins, admin, getAdminByID, - getAdmins + getAdmins, + + createAdmin, + deleteAdmin }; } \ No newline at end of file diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 91d0faec..c2c46a48 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -1,30 +1,58 @@ import {Assistant} from '@/types/Assistant.ts'; +import { Response } from '@/types/Response'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useAssistant() { const assistants = ref(null); const assistant = ref(null); + const response = ref(null); const toast = useToast(); - async function getAssistantByID(id: number) { - const endpoint = endpoints.assistants.retrieve.replace('{id}', id.toString()); + async function getAssistantByID(id: string) { + const endpoint = endpoints.assistants.retrieve.replace('{id}', id); + get(endpoint, assistant, Assistant.fromJSON, toast); + } + + async function getAssistantByCourse(course_id: string) { + const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id); get(endpoint, assistant, Assistant.fromJSON, toast); - console.log(assistant) } async function getAssistants() { const endpoint = endpoints.assistants.index; getList(endpoint, assistants, Assistant.fromJSON, toast); - console.log(assistants.value ? assistants.value.map((assistant, index) => `Assistant ${index + 1}: ${JSON.stringify(assistant)}`) : 'assistants is null'); + } + + 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); + } + + async function createAssistant(assistant_data: any) { + const endpoint = endpoints.assistants.index; + create(endpoint, assistant_data, assistant, Assistant.fromJSON, toast); + } + + async function deleteAssistant(id: string) { + const endpoint = endpoints.admins.retrieve.replace('{id}', id.toString()); + delete_id(endpoint, assistant, Assistant.fromJSON, toast); } return { assistants, assistant, + response, + getAssistantByID, - getAssistants + getAssistantByCourse, + getAssistants, + + createAssistant, + deleteAssistant, + + assistantJoinCourse }; } \ No newline at end of file diff --git a/frontend/src/composables/services/courses.service.ts b/frontend/src/composables/services/courses.service.ts index 9a559a9d..2cc8bfaf 100644 --- a/frontend/src/composables/services/courses.service.ts +++ b/frontend/src/composables/services/courses.service.ts @@ -1,7 +1,7 @@ import {Course} from '@/types/Course.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useCourses() { @@ -9,29 +9,48 @@ export function useCourses() { const course = ref(null); const toast = useToast(); - async function getCourseByID(id: number) { - const endpoint = endpoints.courses.retrieve.replace('{id}', id.toString()); + async function getCourseByID(id: string) { + const endpoint = endpoints.courses.retrieve.replace('{id}', id); get(endpoint, course, Course.fromJSON, toast); - console.log(course.value); } async function getCourses() { const endpoint = endpoints.courses.index; getList(endpoint, courses, Course.fromJSON, toast); - console.log(courses.value ? courses.value.map((course, index) => `Course ${index + 1}: ${JSON.stringify(course)}`) : 'Courses is null'); } - async function getCoursesByStudent(student_id: number) { - const endpoint = endpoints.courses.byStudent.replace('{student_id}', student_id.toString()); + async function createCourse(course_data: any) { + const endpoint = endpoints.courses.index; + create(endpoint, course_data, course, Course.fromJSON, toast); + } + + async function cloneCourse(course_id: string, clone_assistants: boolean) { + const endpoint = endpoints.courses.clone.replace('{course_id}', course_id); + create(endpoint, {clone_assistants: clone_assistants.toString() }, course, Course.fromJSON, toast); + } + + async function deleteCourse(id: string) { + const endpoint = endpoints.courses.retrieve.replace('{id}', id); + delete_id(endpoint, course, Course.fromJSON, toast); + } + + async function getCoursesByStudent(student_id: string) { + const endpoint = endpoints.courses.byStudent.replace('{student_id}', student_id); getList(endpoint, courses, Course.fromJSON, toast); - console.log(courses.value ? courses.value.map((course, index) => `Course ${index + 1}: ${JSON.stringify(course)}`) : 'Courses is null'); } + + return { courses, course, + getCourseByID, getCourses, - getCoursesByStudent + getCoursesByStudent, + + createCourse, + cloneCourse, + deleteCourse }; } \ No newline at end of file diff --git a/frontend/src/composables/services/faculties.service.ts b/frontend/src/composables/services/faculties.service.ts index f94bf559..5a83e1fd 100644 --- a/frontend/src/composables/services/faculties.service.ts +++ b/frontend/src/composables/services/faculties.service.ts @@ -1,7 +1,7 @@ import {Faculty} from '@/types/Faculty.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useFaculty() { @@ -12,19 +12,30 @@ export function useFaculty() { async function getFacultyByID(name: string) { const endpoint = endpoints.faculties.retrieve.replace('{name}', name); get(endpoint, faculty, Faculty.fromJSON, toast); - console.log(faculty) } async function getFacultys() { const endpoint = endpoints.faculties.index; getList(endpoint, faculties, Faculty.fromJSON, toast); - console.log(faculties.value ? faculties.value.map((faculty, index) => `Faculty ${index + 1}: ${JSON.stringify(faculty)}`) : 'Facultys is null'); + } + + async function createFaculty(faculty_data: any) { + const endpoint = endpoints.faculties.index; + create(endpoint, faculty_data, faculty, Faculty.fromJSON, toast); + } + + async function deleteFaculty(id: string) { + const endpoint = endpoints.faculties.retrieve.replace('{id}', id); + delete_id(endpoint, faculty, Faculty.fromJSON, toast); } return { faculties, faculty, getFacultyByID, - getFacultys + getFacultys, + + createFaculty, + deleteFaculty }; } \ No newline at end of file diff --git a/frontend/src/composables/services/groups.service.ts b/frontend/src/composables/services/groups.service.ts index 0125e746..f5b90640 100644 --- a/frontend/src/composables/services/groups.service.ts +++ b/frontend/src/composables/services/groups.service.ts @@ -1,7 +1,7 @@ import {Group} from '@/types/Group.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useGroup() { @@ -9,22 +9,33 @@ export function useGroup() { const group = ref(null); const toast = useToast(); - async function getGroupByID(id: number) { - const endpoint = endpoints.groups.retrieve.replace('{id}', id.toString()); + async function getGroupByID(id: string) { + const endpoint = endpoints.groups.retrieve.replace('{id}', id); get(endpoint, group, Group.fromJSON, toast); - console.log(group) } - async function getGroupsByProject(project_id: number) { - const endpoint = endpoints.groups.byProject.replace('{project_id}', project_id.toString()); + async function getGroupsByProject(project_id: string) { + const endpoint = endpoints.groups.byProject.replace('{project_id}', project_id); getList(endpoint, groups, Group.fromJSON, toast); - console.log(groups.value ? groups.value.map((group, index) => `Group ${index + 1}: ${JSON.stringify(group)}`) : 'Groups is null'); + } + + async function createGroup(group_data: any, group_id: string) { + const endpoint = endpoints.groups.byProject.replace('{group_id}', group_id); + create(endpoint, group_data, group, Group.fromJSON, toast); + } + + async function deleteGroup(id: string) { + const endpoint = endpoints.groups.retrieve.replace('{id}', id); + delete_id(endpoint, group, Group.fromJSON, toast); } return { groups, group, getGroupByID, - getGroupsByProject + getGroupsByProject, + + createGroup, + deleteGroup }; } \ No newline at end of file diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index 3f5a96ca..8d6e8a5c 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -12,8 +12,36 @@ export async function get(endpoint: string, ref: Ref, fromJson: (data }); } -export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T, toast:any): Promise { +export async function create(endpoint: string, data:any, ref: Ref, fromJson: (data: any) => T, toast:any): Promise { + const headers = { + // TODO change this to your token + Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQyODQwMjY1LCJpYXQiOjE3MTEzMDQyNjUsImp0aSI6ImQwYTgxY2YxMzU5NTQ4OWQ4OGNiZDFmZmZiMGI0MmJhIiwidXNlcl9pZCI6IjAwMDIwMTI0NzAxMSJ9.izGK0MStcMiPkOAWs0wgWsYEs0_5S1WvsleWaIcttnk" + }; + await axios.post(endpoint, data, { headers }).then((response: AxiosResponse) => { + ref.value = fromJson(response.data); + //toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + }).catch((error: AxiosError) => { + processError(error, toast); + console.error(error); // Log the error for debugging + }); +} + +export async function delete_id(endpoint: string, ref: Ref, fromJson: (data: any) => T, toast:any): Promise { + const headers = { + // TODO change this to your token + Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQyODQwMjY1LCJpYXQiOjE3MTEzMDQyNjUsImp0aSI6ImQwYTgxY2YxMzU5NTQ4OWQ4OGNiZDFmZmZiMGI0MmJhIiwidXNlcl9pZCI6IjAwMDIwMTI0NzAxMSJ9.izGK0MStcMiPkOAWs0wgWsYEs0_5S1WvsleWaIcttnk" + }; + await axios.delete(endpoint,{ headers }).then((response: AxiosResponse) => { + ref.value = fromJson(response.data); + //toast.add({severity: "success", summary: "Success Message", detail: "Order submitted", life: lifeTime}); + }).catch((error: AxiosError) => { + processError(error, toast); + console.error(error); // Log the error for debugging + }); +} + +export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T, toast:any): Promise { await axios.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}); @@ -45,7 +73,7 @@ export async function getListMerged(endpoints: string[], ref: Ref, ref.value = allData; } -function processError(error: AxiosError, toast:any){ +export function processError(error: AxiosError, toast:any){ if (error.response) { console.log(error.response.status); // The request was made and the server responded with a status code diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index 97737eae..f4003bb7 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -1,9 +1,9 @@ import {Project} from '@/types/Projects.ts'; +import { Course } from '@/types/Course'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; import axios from 'axios'; -import { get, getList, getListMerged } from '@/composables/services/helpers.ts'; -import { Course } from '@/types/Course'; +import { get, getList, getListMerged, create, delete_id, processError } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; @@ -12,16 +12,14 @@ export function useProject() { const project = ref(null); const toast = useToast(); - async function getProjectByID(id: number) { - const endpoint = endpoints.projects.retrieve.replace('{id}', id.toString()); + async function getProjectByID(id: string) { + const endpoint = endpoints.projects.retrieve.replace('{id}', id); get(endpoint, project, Project.fromJSON, toast); - console.log(project) } - async function getProjectsByCourse(course_id: number) { - const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id.toString()); + async function getProjectsByCourse(course_id: string) { + const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id); getList(endpoint, projects, Project.fromJSON, toast); - console.log(projects.value ? projects.value.map((project, index) => `Project ${index + 1}: ${JSON.stringify(project)}`) : 'Projects is null'); } async function getProjectsByStudent(student_id: string) { @@ -34,12 +32,11 @@ export function useProject() { endpList.push(endpoints.projects.byCourse.replace('{course_id}', course.id.toString())); } await getListMerged(endpList, projects, Project.fromJSON, toast); - console.log(projects.value ? projects.value.map((project, index) => `Project ${index + 1}: ${JSON.stringify(project)}`) : 'Projects is null'); } - async function getProjectsByCourseAndDeadline(course_id: number, deadlineDate: Date ) { + async function getProjectsByCourseAndDeadline(course_id: string, deadlineDate: Date ) { - const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id.toString()); + const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id); axios.get(endpoint).then(response => { const allProjects = response.data.map((projectData: Project) => Project.fromJSON(projectData)); @@ -53,10 +50,20 @@ export function useProject() { // Update the projects ref with the filtered projects projects.value = projectsWithMatchingDeadline; }).catch(error => { + processError(error, toast); console.log(error.data); }); + } + - console.log(projects.value ? projects.value.map((project, index) => `Project ${index + 1}: ${JSON.stringify(project)}`) : 'Projects is null'); + async function createProject(project_data: any, course_id: string) { + const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id); + create(endpoint, project_data, project, Project.fromJSON, toast); + } + + async function deleteProject(id: string) { + const endpoint = endpoints.projects.retrieve.replace('{id}', id.toString()); + delete_id(endpoint, project, Project.fromJSON, toast); } return { @@ -65,6 +72,9 @@ export function useProject() { getProjectByID, getProjectsByCourse, getProjectsByCourseAndDeadline, - getProjectsByStudent + getProjectsByStudent, + + createProject, + deleteProject }; } \ No newline at end of file diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index fa50521a..0cbd1b5e 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -1,7 +1,7 @@ import {Structure_check} from '@/types/Structure_check.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useStructure_check() { @@ -9,22 +9,33 @@ export function useStructure_check() { const structure_check = ref(null); const toast = useToast(); - async function getStructure_checkByID(id: number) { - const endpoint = endpoints.structure_checks.retrieve.replace('{id}', id.toString()); + async function getStructure_checkByID(id: string) { + const endpoint = endpoints.structure_checks.retrieve.replace('{id}', id); get(endpoint, structure_check, Structure_check.fromJSON, toast); - console.log(structure_check) } - async function getStructure_checkByProject(project_id: number) { - const endpoint = endpoints.structure_checks.byProject.replace('{project_id}', project_id.toString()); + 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); - console.log(structure_checks.value ? structure_checks.value.map((structure_check, index) => `Structure_check ${index + 1}: ${JSON.stringify(structure_check)}`) : 'Structure_check is null'); + } + + async function createStructure_check(structure_check_data: any, 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); + } + + async function deleteStructure_check(id: string) { + const endpoint = endpoints.structure_checks.retrieve.replace('{id}', id); + delete_id(endpoint, structure_check, Structure_check.fromJSON, toast); } return { structure_checks, structure_check, getStructure_checkByID, - getStructure_checkByProject + getStructure_checkByProject, + + createStructure_check, + deleteStructure_check }; } \ No newline at end of file diff --git a/frontend/src/composables/services/students.service.ts b/frontend/src/composables/services/students.service.ts index 1812ef5a..7dc60f8e 100644 --- a/frontend/src/composables/services/students.service.ts +++ b/frontend/src/composables/services/students.service.ts @@ -1,30 +1,77 @@ import {Student} from '@/types/Student'; +import { Response } from '@/types/Response'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useStudents() { const students = ref(null); const student = ref(null); + const response = ref(null); const toast = useToast(); - async function getStudentByID(id: number) { - const endpoint = endpoints.students.retrieve.replace('{id}', id.toString()); + async function getStudentByID(id: string) { + const endpoint = endpoints.students.retrieve.replace('{id}', id); get(endpoint, student, Student.fromJSON, toast); - console.log(student) } async function getStudents() { const endpoint = endpoints.students.index; getList(endpoint, students, Student.fromJSON, toast); - console.log(students.value ? students.value.map((student, index) => `Student ${index + 1}: ${JSON.stringify(student)}`) : 'Students is null'); + } + + async function getStudentsbyCourse(course_id: string) { + const endpoint = endpoints.students.byCourse.replace('{course_id}', course_id); + getList(endpoint, students, Student.fromJSON, toast); + } + + async function getStudentsbyGroup(group_id: string) { + const endpoint = endpoints.students.byGroup.replace('{group_id}', group_id); + getList(endpoint, students, Student.fromJSON, toast); + } + + 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); + } + + async function studentLeaveCourse(course_id: string, student_id: string) { + const endpoint = endpoints.students.byCourse.replace('{course_id}', course_id); + delete_id(endpoint, {student_id: student_id}, response, Response.fromJSON, toast); + } + + 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); + } + + async function createStudent(student_data: any) { + const endpoint = endpoints.students.index; + create(endpoint, student_data, student, Student.fromJSON, toast); + } + + async function deleteStudent(id: string) { + const endpoint = endpoints.students.retrieve.replace('{id}', id); + delete_id(endpoint, student, Student.fromJSON, toast); } return { students, student, + + response, + getStudentByID, - getStudents + getStudents, + getStudentsbyCourse, + getStudentsbyGroup, + + createStudent, + deleteStudent, + + studentJoinCourse, + studentLeaveCourse, + studentJoinGroup }; } \ No newline at end of file diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index 248d9124..f7847a89 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -1,7 +1,7 @@ import {Submission} from '@/types/Submission.ts'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useSubmission() { @@ -9,22 +9,29 @@ export function useSubmission() { const submission = ref(null); const toast = useToast(); - async function getSubmissionByID(id: number) { - const endpoint = endpoints.submissions.retrieve.replace('{id}', id.toString()); + async function getSubmissionByID(id: string) { + const endpoint = endpoints.submissions.retrieve.replace('{id}', id); get(endpoint, submission, Submission.fromJSON, toast); - console.log(submission) } - async function getSubmissionByProject(project_id: number) { - const endpoint = endpoints.submissions.byProject.replace('{project_id}', project_id.toString()); + async function getSubmissionByProject(project_id: string) { + const endpoint = endpoints.submissions.byProject.replace('{project_id}', project_id); getList(endpoint, submissions, Submission.fromJSON, toast); - console.log(submissions.value ? submissions.value.map((submission, index) => `Submission ${index + 1}: ${JSON.stringify(submission)}`) : 'Submission is null'); } - async function getSubmissionByGroup(group_id: number) { - const endpoint = endpoints.submissions.byGroup.replace('{group_id}', group_id.toString()); + async function getSubmissionByGroup(group_id: string) { + const endpoint = endpoints.submissions.byGroup.replace('{group_id}', group_id); getList(endpoint, submissions, Submission.fromJSON, toast); - console.log(submissions.value ? submissions.value.map((submission, index) => `Submission ${index + 1}: ${JSON.stringify(submission)}`) : 'Submission is null'); + } + + async function createSubmission(submission_data: any, group_id: string) { + const endpoint = endpoints.submissions.byGroup.replace('{group_id}', group_id); + create(endpoint, submission_data, submission, Submission.fromJSON, toast); + } + + async function deleteSubmission(id: string) { + const endpoint = endpoints.submissions.retrieve.replace('{id}', id); + delete_id(endpoint, submission, Submission.fromJSON, toast); } return { @@ -32,6 +39,9 @@ export function useSubmission() { submission, getSubmissionByID, getSubmissionByProject, - getSubmissionByGroup + getSubmissionByGroup, + + createSubmission, + deleteSubmission }; } \ No newline at end of file diff --git a/frontend/src/composables/services/submissionStatus.service.ts b/frontend/src/composables/services/submissionStatus.service.ts index dada2f91..fe631157 100644 --- a/frontend/src/composables/services/submissionStatus.service.ts +++ b/frontend/src/composables/services/submissionStatus.service.ts @@ -8,10 +8,9 @@ export function useSubmission() { const submissionStatus = ref(null); const toast = useToast(); - async function getSubmissionStatus(project_id: number) { - const endpoint = endpoints.submissions.status.replace('{project_id}', project_id.toString()); + async function getSubmissionStatus(project_id: string) { + const endpoint = endpoints.submissions.status.replace('{project_id}', project_id); get(endpoint, submissionStatus, SubmissionStatus.fromJSON, toast); - console.log(submissionStatus) } return { diff --git a/frontend/src/composables/services/teachers.service.ts b/frontend/src/composables/services/teachers.service.ts index 1b5d7252..671b3fe6 100644 --- a/frontend/src/composables/services/teachers.service.ts +++ b/frontend/src/composables/services/teachers.service.ts @@ -1,30 +1,58 @@ import {Teacher} from '@/types/Teacher.ts'; +import { Response } from '@/types/Response'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useTeacher() { const teachers = ref(null); const teacher = ref(null); + const response = ref(null); const toast = useToast(); - async function getTeacherByID(id: number) { - const endpoint = endpoints.teachers.retrieve.replace('{id}', id.toString()); + async function getTeacherByID(id: string) { + const endpoint = endpoints.teachers.retrieve.replace('{id}', id); + get(endpoint, teacher, Teacher.fromJSON, toast); + } + + async function getTeacherByCourse(course_id: string) { + const endpoint = endpoints.teachers.byCourse.replace('{course_id}', course_id); get(endpoint, teacher, Teacher.fromJSON, toast); - console.log(teacher) } async function getTeachers() { const endpoint = endpoints.teachers.index; getList(endpoint, teachers, Teacher.fromJSON, toast); - console.log(teachers.value ? teachers.value.map((teacher, index) => `Teacher ${index + 1}: ${JSON.stringify(teacher)}`) : 'Teachers is null'); + } + + 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); + } + + async function createTeacher(teacher_data: any) { + const endpoint = endpoints.teachers.index; + create(endpoint, teacher_data, teacher, Teacher.fromJSON, toast); + } + + async function deleteTeacher(id: string) { + const endpoint = endpoints.students.retrieve.replace('{id}', id); + delete_id(endpoint, teacher, Teacher.fromJSON, toast); } return { teachers, teacher, + response, + getTeacherByID, - getTeachers + getTeacherByCourse, + getTeachers, + + createTeacher, + deleteTeacher, + + teacherJoinCourse }; } \ No newline at end of file diff --git a/frontend/src/config/endpoints.ts b/frontend/src/config/endpoints.ts index bc637c6f..d832aa29 100644 --- a/frontend/src/config/endpoints.ts +++ b/frontend/src/config/endpoints.ts @@ -6,19 +6,24 @@ export const endpoints = { courses: { index: '/api/courses/', retrieve: '/api/courses/{id}/', - byStudent: '/api/students/{student_id}/courses/' + byStudent: '/api/students/{student_id}/courses/', + clone: '/api/courses/{course_id}/clone/' }, students: { index: '/api/students/', - retrieve: '/api/students/{id}/' + retrieve: '/api/students/{id}/', + byCourse: '/api/courses/{course_id}/students/', + byGroup: '/api/groups/{group_id}/students/' }, teachers: { index: '/api/teachers/', - retrieve: '/api/teachers/{id}/' + retrieve: '/api/teachers/{id}/', + byCourse: '/api/courses/{course_id}/teachers/' }, assistants: { index: '/api/assistants/', - retrieve: '/api/assistants/{id}/' + retrieve: '/api/assistants/{id}/', + byCourse: '/api/courses/{course_id}/assistants/' }, admins: { index: '/api/admins/', diff --git a/frontend/src/types/Response.ts b/frontend/src/types/Response.ts new file mode 100644 index 00000000..c447b628 --- /dev/null +++ b/frontend/src/types/Response.ts @@ -0,0 +1,15 @@ +export class Response { + constructor( + public message: string, + ) { + } + + /** + * Convert a response object to a response instance. + * + * @param response + */ + static fromJSON(response: Response): Response { + return new Response(response.message); + } +} \ No newline at end of file diff --git a/frontend/src/views/dashboard/DashboardView.vue b/frontend/src/views/dashboard/DashboardView.vue index 7cd0fe90..292fd9dc 100644 --- a/frontend/src/views/dashboard/DashboardView.vue +++ b/frontend/src/views/dashboard/DashboardView.vue @@ -4,23 +4,55 @@ import Button from 'primevue/button'; import CourseCard from '@/components/courses/CourseCard.vue'; import BaseLayout from '@/components/layout/BaseLayout.vue'; import Title from '@/components/Title.vue'; -import {useI18n} from 'vue-i18n'; -import {PrimeIcons} from 'primevue/api'; -import {onMounted } from 'vue'; +import { useI18n } from 'vue-i18n'; +import { PrimeIcons } from 'primevue/api'; +import { onMounted } from 'vue'; import { useCourses } from '@/composables/services/courses.service.ts'; +import { useStudents } from '@/composables/services/students.service.ts'; +import { Course } from '@/types/Course.ts'; +import {ref} from 'vue'; /* Composable injections */ const { t } = useI18n(); /* Service injection */ -const { courses, getCoursesByStudent } = useCourses(); +const { courses, getCoursesByStudent, createCourse, deleteCourse } = useCourses(); +const { studentJoinCourse } = useStudents(); onMounted(async () => { console.log("fetching courses"); - await getCoursesByStudent(1); // TODO make this the id of the logged in user + await getCoursesByStudent("1"); // TODO make this the id of the logged in user }); +// test code vvvv + +const idValue = ref(''); +const vaknaam = ref(''); + +// Method to execute when the button is clicked +const executeCode = () => { + // Put your code here that you want to execute + console.log('Button clicked! Code executed.'); + createCourse({name: vaknaam.value, academic_startyear:2023}); +}; + +// Function to handle form submission +const handleSubmit = () => { + // Perform actions here, such as sending the input value to a backend API + console.log('Submitted value:', idValue.value); + studentJoinCourse(idValue.value, "1"); +}; + +// Function to handle form submission +const handleDelete = () => { + // Perform actions here, such as sending the input value to a backend API + console.log('Submitted value:', idValue.value); + deleteCourse(idValue.value); +}; + +// test code ^^^^ +