-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from SELab-2/services
Services
- Loading branch information
Showing
15 changed files
with
365 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
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() { | ||
const admins = ref<Admin[]|null>(null); | ||
const admin = ref<Admin|null>(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<Admin>(endpoint, admin, Admin.fromJSON, toast); | ||
console.log(admin) | ||
} | ||
|
||
async function getAdmins() { | ||
const endpoint = endpoints.admins.index; | ||
getList<Admin>(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<Admin>(endpoint, admin_data, admin, Admin.fromJSON, toast); | ||
} | ||
|
||
async function deleteAdmin(id: string) { | ||
const endpoint = endpoints.admins.retrieve.replace('{id}', id.toString()); | ||
delete_id<Admin>(endpoint, admin, Admin.fromJSON, toast); | ||
} | ||
|
||
return { | ||
admins, | ||
admin, | ||
getAdminByID, | ||
getAdmins | ||
getAdmins, | ||
|
||
createAdmin, | ||
deleteAdmin | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Assistant[]|null>(null); | ||
const assistant = ref<Assistant|null>(null); | ||
const response = ref<Response|null>(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<Assistant>(endpoint, assistant, Assistant.fromJSON, toast); | ||
} | ||
|
||
async function getAssistantByCourse(course_id: string) { | ||
const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id); | ||
get<Assistant>(endpoint, assistant, Assistant.fromJSON, toast); | ||
console.log(assistant) | ||
} | ||
|
||
async function getAssistants() { | ||
const endpoint = endpoints.assistants.index; | ||
getList<Assistant>(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<Response>(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON, toast); | ||
} | ||
|
||
async function createAssistant(assistant_data: any) { | ||
const endpoint = endpoints.assistants.index; | ||
create<Assistant>(endpoint, assistant_data, assistant, Assistant.fromJSON, toast); | ||
} | ||
|
||
async function deleteAssistant(id: string) { | ||
const endpoint = endpoints.admins.retrieve.replace('{id}', id.toString()); | ||
delete_id<Assistant>(endpoint, assistant, Assistant.fromJSON, toast); | ||
} | ||
|
||
return { | ||
assistants, | ||
assistant, | ||
response, | ||
|
||
getAssistantByID, | ||
getAssistants | ||
getAssistantByCourse, | ||
getAssistants, | ||
|
||
createAssistant, | ||
deleteAssistant, | ||
|
||
assistantJoinCourse | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,56 @@ | ||
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() { | ||
const courses = ref<Course[]|null>(null); | ||
const course = ref<Course|null>(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<Course>(endpoint, course, Course.fromJSON, toast); | ||
console.log(course.value); | ||
} | ||
|
||
async function getCourses() { | ||
const endpoint = endpoints.courses.index; | ||
getList<Course>(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<Course>(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<Course>(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<Course>(endpoint, course, Course.fromJSON, toast); | ||
} | ||
|
||
async function getCoursesByStudent(student_id: string) { | ||
const endpoint = endpoints.courses.byStudent.replace('{student_id}', student_id); | ||
getList<Course>(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 | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
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() { | ||
const groups = ref<Group[]|null>(null); | ||
const group = ref<Group|null>(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<Group>(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<Group>(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<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 | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.