Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Services #183

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions frontend/src/composables/services/admins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@ import {Admin} from '@/types/Admin.ts';
import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList, create, delete_id } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useAdmin() {
const admins = ref<Admin[]|null>(null);
const admin = ref<Admin|null>(null);
const toast = useToast();

async function getAdminByID(id: string, t: ComposerTranslation) {
async function getAdminByID(id: string) {
const endpoint = endpoints.admins.retrieve.replace('{id}', id);
get<Admin>(endpoint, admin, Admin.fromJSON, toast, t);
await get<Admin>(endpoint, admin, Admin.fromJSON);
}

async function getAdmins(t: ComposerTranslation) {
async function getAdmins() {
const endpoint = endpoints.admins.index;
getList<Admin>(endpoint, admins, Admin.fromJSON, toast, t);
await getList<Admin>(endpoint, admins, Admin.fromJSON);
}

async function createAdmin(admin_data: any, t: ComposerTranslation) {
async function createAdmin(admin_data: Admin) {
const endpoint = endpoints.admins.index;
create<Admin>(endpoint, admin_data, admin, Admin.fromJSON, toast, t);
await create<Admin>(endpoint,
{
email:admin_data.email,
first_name:admin_data.first_name,
last_name: admin_data.last_name
},
admin, Admin.fromJSON);
}

async function deleteAdmin(id: string, t: ComposerTranslation) {
async function deleteAdmin(id: string) {
const endpoint = endpoints.admins.retrieve.replace('{id}', id);
delete_id<Admin>(endpoint, admin, Admin.fromJSON, toast, t);
await delete_id<Admin>(endpoint, admin, Admin.fromJSON);
}

return {
Expand Down
37 changes: 20 additions & 17 deletions frontend/src/composables/services/assistant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,51 @@ import { Response } from '@/types/Response';
import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList, create, delete_id, delete_id_with_data } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useAssistant() {
const assistants = ref<Assistant[]|null>(null);
const assistant = ref<Assistant|null>(null);
const response = ref<Response|null>(null);
const toast = useToast();

async function getAssistantByID(id: string, t: ComposerTranslation) {
async function getAssistantByID(id: string) {
const endpoint = endpoints.assistants.retrieve.replace('{id}', id);
get<Assistant>(endpoint, assistant, Assistant.fromJSON, toast, t);
await get<Assistant>(endpoint, assistant, Assistant.fromJSON);
}

async function getAssistantByCourse(course_id: string, t: ComposerTranslation) {
async function getAssistantByCourse(course_id: string) {
const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id);
get<Assistant>(endpoint, assistant, Assistant.fromJSON, toast, t);
await get<Assistant>(endpoint, assistant, Assistant.fromJSON);
}

async function getAssistants(t: ComposerTranslation) {
async function getAssistants() {
const endpoint = endpoints.assistants.index;
getList<Assistant>(endpoint, assistants, Assistant.fromJSON, toast, t);
await getList<Assistant>(endpoint, assistants, Assistant.fromJSON);
}

async function assistantJoinCourse(course_id: string, assistant_id: string, t: ComposerTranslation) {
async function assistantJoinCourse(course_id: string, assistant_id: string) {
const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id);
create<Response>(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON, toast, t);
await create<Response>(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON);
}

async function assistantLeaveCourse(course_id: string, assistant_id: string, t: ComposerTranslation) {
async function assistantLeaveCourse(course_id: string, assistant_id: string) {
const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id);
delete_id_with_data<Response>(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON, toast, t);
await delete_id_with_data<Response>(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON);
}

async function createAssistant(assistant_data: any, t: ComposerTranslation) {
async function createAssistant(assistant_data: Assistant) {
const endpoint = endpoints.assistants.index;
create<Assistant>(endpoint, assistant_data, assistant, Assistant.fromJSON, toast, t);
await create<Assistant>(endpoint,
{
email:assistant_data.email,
first_name:assistant_data.first_name,
last_name: assistant_data.last_name
},
assistant, Assistant.fromJSON);
}

async function deleteAssistant(id: string, t: ComposerTranslation) {
async function deleteAssistant(id: string) {
const endpoint = endpoints.admins.retrieve.replace('{id}', id);
delete_id<Assistant>(endpoint, assistant, Assistant.fromJSON, toast, t);
await delete_id<Assistant>(endpoint, assistant, Assistant.fromJSON);
}

return {
Expand Down
33 changes: 18 additions & 15 deletions frontend/src/composables/services/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,45 @@ import {Course} from '@/types/Course.ts';
import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList, create, delete_id } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useCourses() {
const courses = ref<Course[]|null>(null);
const course = ref<Course|null>(null);
const toast = useToast();

async function getCourseByID(id: string, t: ComposerTranslation) {
async function getCourseByID(id: string) {
const endpoint = endpoints.courses.retrieve.replace('{id}', id);
await get<Course>(endpoint, course, Course.fromJSON, toast, t);
await get<Course>(endpoint, course, Course.fromJSON);
}

async function getCourses(t: ComposerTranslation) {
async function getCourses() {
const endpoint = endpoints.courses.index;
await getList<Course>(endpoint, courses, Course.fromJSON, toast, t);
await getList<Course>(endpoint, courses, Course.fromJSON);
}

async function getCoursesByStudent(student_id: string, t: ComposerTranslation) {
async function getCoursesByStudent(student_id: string) {
const endpoint = endpoints.courses.byStudent.replace('{student_id}', student_id);
await getList<Course>(endpoint, courses, Course.fromJSON, toast, t);
await getList<Course>(endpoint, courses, Course.fromJSON);
}

async function createCourse(course_data: any, t: ComposerTranslation) {
async function createCourse(course_data: Course) {
const endpoint = endpoints.courses.index;
await create<Course>(endpoint, course_data, course, Course.fromJSON, toast, t);
await create<Course>(endpoint,
{
name: course_data.name,
description: course_data.description,
academic_startyear: course_data.academic_startyear
},
course, Course.fromJSON);
}

async function cloneCourse(course_id: string, clone_assistants: boolean, t: ComposerTranslation) {
async function cloneCourse(course_id: string, clone_assistants: boolean) {
const endpoint = endpoints.courses.clone.replace('{course_id}', course_id);
await create<Course>(endpoint, {clone_assistants: clone_assistants.toString() }, course, Course.fromJSON, toast, t);
await create<Course>(endpoint, {clone_assistants: clone_assistants.toString() }, course, Course.fromJSON);
}

async function deleteCourse(id: string, t: ComposerTranslation) {
async function deleteCourse(id: string) {
const endpoint = endpoints.courses.retrieve.replace('{id}', id);
await delete_id<Course>(endpoint, course, Course.fromJSON, toast, t);
await delete_id<Course>(endpoint, course, Course.fromJSON);
}

return {
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/composables/services/faculties.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@ import {Faculty} from '@/types/Faculty.ts';
import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList, create, delete_id } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useFaculty() {
const faculties = ref<Faculty[]|null>(null);
const faculty = ref<Faculty|null>(null);
const toast = useToast();

async function getFacultyByID(name: string, t: ComposerTranslation) {
async function getFacultyByID(name: string) {
const endpoint = endpoints.faculties.retrieve.replace('{name}', name);
get<Faculty>(endpoint, faculty, Faculty.fromJSON, toast, t);
await get<Faculty>(endpoint, faculty, Faculty.fromJSON);
}

async function getFacultys(t: ComposerTranslation) {
async function getFacultys() {
const endpoint = endpoints.faculties.index;
getList<Faculty>(endpoint, faculties, Faculty.fromJSON, toast, t);
await getList<Faculty>(endpoint, faculties, Faculty.fromJSON);
}

async function createFaculty(faculty_data: any, t: ComposerTranslation) {
async function createFaculty(faculty_data: Faculty) {
const endpoint = endpoints.faculties.index;
create<Faculty>(endpoint, faculty_data, faculty, Faculty.fromJSON, toast, t);
await create<Faculty>(endpoint, {name: faculty_data.name}, faculty, Faculty.fromJSON);
}

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

return {
Expand Down
23 changes: 12 additions & 11 deletions frontend/src/composables/services/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@ import {Group} from '@/types/Group.ts';
import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList, create, delete_id } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useGroup() {
const groups = ref<Group[]|null>(null);
const group = ref<Group|null>(null);
const toast = useToast();

async function getGroupByID(id: string, t: ComposerTranslation) {
async function getGroupByID(id: string) {
const endpoint = endpoints.groups.retrieve.replace('{id}', id);
get<Group>(endpoint, group, Group.fromJSON, toast, t);
await get<Group>(endpoint, group, Group.fromJSON);
}

async function getGroupsByProject(project_id: string, t: ComposerTranslation) {
async function getGroupsByProject(project_id: string) {
const endpoint = endpoints.groups.byProject.replace('{project_id}', project_id);
getList<Group>(endpoint, groups, Group.fromJSON, toast, t);
await getList<Group>(endpoint, groups, Group.fromJSON);
}

async function createGroup(group_data: any, group_id: string, t: ComposerTranslation) {
async function createGroup(group_data: Group, group_id: string) {
const endpoint = endpoints.groups.byProject.replace('{group_id}', group_id);
create<Group>(endpoint, group_data, group, Group.fromJSON, toast, t);
await create<Group>(endpoint,
{
score: group_data.score
},
group, Group.fromJSON);
}

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

return {
Expand Down
Loading
Loading