From da6334228f5fbbc8fc56ccaea40b185ec641db63 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Mon, 25 Mar 2024 12:01:14 +0100 Subject: [PATCH] chore: faculty, groups, students create and delete services added --- .../composables/services/faculties.service.ts | 17 +++++++++++++++-- .../src/composables/services/groups.service.ts | 17 +++++++++++++++-- .../composables/services/students.service.ts | 15 ++++++++++++++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/frontend/src/composables/services/faculties.service.ts b/frontend/src/composables/services/faculties.service.ts index f94bf559..d46cfa05 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() { @@ -21,10 +21,23 @@ export function useFaculty() { 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.toString()); + 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..c46ca362 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() { @@ -21,10 +21,23 @@ export function useGroup() { 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/students.service.ts b/frontend/src/composables/services/students.service.ts index 9c390ded..008d7ed4 100644 --- a/frontend/src/composables/services/students.service.ts +++ b/frontend/src/composables/services/students.service.ts @@ -2,7 +2,7 @@ import {Student} from '@/types/Student'; import { Response } from '@/types/Response'; import {ref} from 'vue'; import {endpoints} from '@/config/endpoints.ts'; -import { get, getList, create } from '@/composables/services/helpers.ts'; +import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; import { useToast } from 'primevue/usetoast'; export function useStudents() { @@ -36,6 +36,16 @@ export function useStudents() { 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.toString()); + delete_id(endpoint, student, Student.fromJSON, toast); + } + return { students, student, @@ -47,6 +57,9 @@ export function useStudents() { getStudentsbyCourse, getStudentsbyGroup, + createStudent, + deleteStudent, + studentJoinCourse, }; } \ No newline at end of file