Skip to content

Commit

Permalink
chore: faculty, groups, students create and delete services added
Browse files Browse the repository at this point in the history
  • Loading branch information
tyboro2002 committed Mar 25, 2024
1 parent f18a5cd commit da63342
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
17 changes: 15 additions & 2 deletions frontend/src/composables/services/faculties.service.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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<Faculty>(endpoint, faculty_data, faculty, Faculty.fromJSON, toast);
}

async function deleteFaculty(id: string) {
const endpoint = endpoints.faculties.retrieve.replace('{id}', id.toString());
delete_id<Faculty>(endpoint, faculty, Faculty.fromJSON, toast);
}

return {
faculties,
faculty,
getFacultyByID,
getFacultys
getFacultys,

createFaculty,
deleteFaculty
};
}
17 changes: 15 additions & 2 deletions frontend/src/composables/services/groups.service.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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<Group>(endpoint, group_data, group, Group.fromJSON, toast);
}

async function deleteGroup(id: string) {
const endpoint = endpoints.groups.retrieve.replace('{id}', id);
delete_id<Group>(endpoint, group, Group.fromJSON, toast);
}

return {
groups,
group,
getGroupByID,
getGroupsByProject
getGroupsByProject,

createGroup,
deleteGroup
};
}
15 changes: 14 additions & 1 deletion frontend/src/composables/services/students.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -36,6 +36,16 @@ export function useStudents() {
create<Response>(endpoint, {student_id: student_id}, response, Response.fromJSON, toast);
}

async function createStudent(student_data: any) {
const endpoint = endpoints.students.index;
create<Student>(endpoint, student_data, student, Student.fromJSON, toast);
}

async function deleteStudent(id: string) {
const endpoint = endpoints.students.retrieve.replace('{id}', id.toString());
delete_id<Student>(endpoint, student, Student.fromJSON, toast);
}

return {
students,
student,
Expand All @@ -47,6 +57,9 @@ export function useStudents() {
getStudentsbyCourse,
getStudentsbyGroup,

createStudent,
deleteStudent,

studentJoinCourse,
};
}

0 comments on commit da63342

Please sign in to comment.