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

chore: add student service #147

Merged
merged 21 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
25fe026
chore: add student service
tyboro2002 Mar 21, 2024
636bc90
chore: add faculty and teacher services
tyboro2002 Mar 21, 2024
4efcda8
Merge branch 'development' of https://github.com/SELab-2/UGent-7 into…
tyboro2002 Mar 21, 2024
da3b996
chore:completed teacher service scaffolding
tyboro2002 Mar 21, 2024
4b8df18
chore:completed teacher service scaffolding
tyboro2002 Mar 21, 2024
ada1663
chore: added admin service and fixed some things in teacher and stude…
tyboro2002 Mar 21, 2024
1bb063f
chore: add assistant service
tyboro2002 Mar 21, 2024
65cd4f6
chore: testing if courses service works + adding all course service
tyboro2002 Mar 22, 2024
25cf971
Merge branch 'services' of https://github.com/SELab-2/UGent-7 into se…
tyboro2002 Mar 22, 2024
944222b
chore: make dashboard display courses from api
tyboro2002 Mar 22, 2024
12bc8de
chore: add project type
tyboro2002 Mar 22, 2024
0377726
chore: add project service
tyboro2002 Mar 22, 2024
61f1151
chore: add submision service
tyboro2002 Mar 22, 2024
bb5478d
chore: add structure_check service
tyboro2002 Mar 22, 2024
5b101d6
chore: add all admins service
tyboro2002 Mar 22, 2024
fe6368b
chore: add all assistants service
tyboro2002 Mar 22, 2024
e8ba1a9
chore: add all assistants service
tyboro2002 Mar 22, 2024
d69d6eb
chore: add all teachers service
tyboro2002 Mar 22, 2024
e114d4e
chore: add all facultys service
tyboro2002 Mar 22, 2024
5561720
chore: add projects by date course service
tyboro2002 Mar 22, 2024
59d9095
fix: fix comments of bram
tyboro2002 Mar 22, 2024
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
40 changes: 40 additions & 0 deletions frontend/src/composables/services/admins.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Admin} from '@/types/Admin.ts';
import {ref} from 'vue';
import axios from 'axios';
import {endpoints} from '@/config/endpoints.ts';

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

async function getAdminByID(id: number) {
const endpoint = endpoints.admins.retrieve.replace('{id}', id.toString());

axios.get(endpoint).then(response => {
admin.value = Admin.fromJSON(response.data);
}).catch(error => {
console.log(error.data);
});

console.log(admin)
}

async function getAdmins() {
const endpoint = endpoints.admins.index;

axios.get(endpoint).then(response => {
admins.value = response.data.map((adminData: Admin) => Admin.fromJSON(adminData));
}).catch(error => {
console.log(error.data);
});

console.log(admins.value ? admins.value.map((admin, index) => `Admin ${index + 1}: ${JSON.stringify(admin)}`) : 'Admins is null');
}

return {
admins,
admin,
getAdminByID,
getAdmins
};
}
40 changes: 40 additions & 0 deletions frontend/src/composables/services/assistant.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Assistant} from '@/types/Assistant.ts';
import {ref} from 'vue';
import axios from 'axios';
import {endpoints} from '@/config/endpoints.ts';

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

async function getAssistantByID(id: number) {
const endpoint = endpoints.assistants.retrieve.replace('{id}', id.toString());

axios.get(endpoint).then(response => {
assistant.value = Assistant.fromJSON(response.data);
}).catch(error => {
console.log(error.data);
});

console.log(assistant)
}

async function getAssistants() {
const endpoint = endpoints.assistants.index;

axios.get(endpoint).then(response => {
assistants.value = response.data.map((assistantData: Assistant) => Assistant.fromJSON(assistantData));
}).catch(error => {
console.log(error.data);
});

console.log(assistants.value ? assistants.value.map((assistant, index) => `Assistant ${index + 1}: ${JSON.stringify(assistant)}`) : 'assistants is null');
}

return {
assistants,
assistant,
getAssistantByID,
getAssistants
};
}
30 changes: 28 additions & 2 deletions frontend/src/composables/services/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,38 @@ export function useCourses() {
console.log(error.data);
});

console.log(Course)
console.log(course)
}

async function getCourses() {
const endpoint = endpoints.courses.index;

axios.get(endpoint).then(response => {
courses.value = response.data.map((courseData: Course) => Course.fromJSON(courseData));
}).catch(error => {
console.log(error.data);
});

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());

axios.get(endpoint).then(response => {
courses.value = response.data.map((courseData: Course) => Course.fromJSON(courseData));
}).catch(error => {
console.log(error.data);
});

console.log(courses.value ? courses.value.map((course, index) => `Course ${index + 1}: ${JSON.stringify(course)}`) : 'Courses is null');
}

return {
courses,
course,
getCourseByID
getCourseByID,
getCourses,
getCoursesByStudent
};
}
40 changes: 40 additions & 0 deletions frontend/src/composables/services/faculties.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Faculty} from '@/types/Faculty.ts';
import {ref} from 'vue';
import axios from 'axios';
import {endpoints} from '@/config/endpoints.ts';

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

async function getFacultyByID(name: string) {
const endpoint = endpoints.faculties.retrieve.replace('{name}', name);

axios.get(endpoint).then(response => {
faculty.value = Faculty.fromJSON(response.data);
}).catch(error => {
console.log(error.data);
});

console.log(faculty)
}

async function getFacultys() {
const endpoint = endpoints.faculties.index;

axios.get(endpoint).then(response => {
faculties.value = response.data.map((facultyData: Faculty) => Faculty.fromJSON(facultyData));
}).catch(error => {
console.log(error.data);
});

console.log(faculties.value ? faculties.value.map((faculty, index) => `Faculty ${index + 1}: ${JSON.stringify(faculty)}`) : 'Facultys is null');
}

return {
faculties,
faculty,
getFacultyByID,
getFacultys
};
}
40 changes: 40 additions & 0 deletions frontend/src/composables/services/groups.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Group} from '@/types/Group.ts';
import {ref} from 'vue';
import axios from 'axios';
import {endpoints} from '@/config/endpoints.ts';

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

async function getGroupByID(id: number) {
const endpoint = endpoints.groups.retrieve.replace('{id}', id.toString());

axios.get(endpoint).then(response => {
group.value = Group.fromJSON(response.data);
}).catch(error => {
console.log(error.data);
});

console.log(group)
}

async function getGroupsByProject(project_id: number) {
const endpoint = endpoints.groups.byProject.replace('{project_id}', project_id.toString());

axios.get(endpoint).then(response => {
groups.value = response.data.map((groupData: Group) => Group.fromJSON(groupData));
}).catch(error => {
console.log(error.data);
});

console.log(groups.value ? groups.value.map((group, index) => `Group ${index + 1}: ${JSON.stringify(group)}`) : 'Groups is null');
}

return {
groups,
group,
getGroupByID,
getGroupsByProject
};
}
11 changes: 11 additions & 0 deletions frontend/src/composables/services/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
import axios from 'axios';

export function get<T extends Model>(path: string, ref: Ref<T>): void {
axios.get(path).then(response =>
ref.value = ref.fromJSON(response.data)
).catch(error => {
console.log(error.data);
});
}
*/
63 changes: 63 additions & 0 deletions frontend/src/composables/services/project.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {Project} from '@/types/Projects.ts';
import {ref} from 'vue';
import axios from 'axios';
import {endpoints} from '@/config/endpoints.ts';

export function useProject() {
const projects = ref<Project[]|null>(null);
const project = ref<Project|null>(null);

async function getProjectByID(id: number) {
const endpoint = endpoints.projects.retrieve.replace('{id}', id.toString());

axios.get(endpoint).then(response => {
project.value = Project.fromJSON(response.data);
}).catch(error => {
console.log(error.data);
});

console.log(project)
}

async function getProjectsByCourse(course_id: number) {
const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id.toString());

axios.get(endpoint).then(response => {
projects.value = response.data.map((projectData: Project) => Project.fromJSON(projectData));
}).catch(error => {
console.log(error.data);
});

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 ) {

const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id.toString());

axios.get(endpoint).then(response => {
const allProjects = response.data.map((projectData: Project) => Project.fromJSON(projectData));

// Filter projects based on the deadline date
const projectsWithMatchingDeadline = allProjects.filter((project: Project) => {
const projectDeadlineDate = project.deadline;
return projectDeadlineDate.toDateString() === deadlineDate.toDateString();
});

// Update the projects ref with the filtered projects
projects.value = projectsWithMatchingDeadline;
}).catch(error => {
console.log(error.data);
});

console.log(projects.value ? projects.value.map((project, index) => `Project ${index + 1}: ${JSON.stringify(project)}`) : 'Projects is null');
}

return {
projects,
project,
getProjectByID,
getProjectsByCourse,
getProjectsByCourseAndDeadline
};
}
40 changes: 40 additions & 0 deletions frontend/src/composables/services/structure_check.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Structure_check} from '@/types/Structure_check.ts';
import {ref} from 'vue';
import axios from 'axios';
import {endpoints} from '@/config/endpoints.ts';

export function useStructure_check() {
const structure_checks = ref<Structure_check[]|null>(null);
const structure_check = ref<Structure_check|null>(null);

async function getStructure_checkByID(id: number) {
const endpoint = endpoints.structure_checks.retrieve.replace('{id}', id.toString());

axios.get(endpoint).then(response => {
structure_check.value = Structure_check.fromJSON(response.data);
}).catch(error => {
console.log(error.data);
});

console.log(structure_check)
}

async function getStructure_checkByProject(project_id: number) {
const endpoint = endpoints.structure_checks.byProject.replace('{project_id}', project_id.toString());

axios.get(endpoint).then(response => {
structure_checks.value = response.data.map((structure_checkData: Structure_check) => Structure_check.fromJSON(structure_checkData));
}).catch(error => {
console.log(error.data);
});

console.log(structure_checks.value ? structure_checks.value.map((structure_check, index) => `Structure_check ${index + 1}: ${JSON.stringify(structure_check)}`) : 'Structure_check is null');
}

return {
structure_checks,
structure_check,
getStructure_checkByID,
getStructure_checkByProject
};
}
40 changes: 40 additions & 0 deletions frontend/src/composables/services/students.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Student} from '@/types/Student';
import {ref} from 'vue';
import axios from 'axios';
import {endpoints} from '@/config/endpoints.ts';

export function useStudents() {
const students = ref<Student[]|null>(null);
const student = ref<Student|null>(null);

async function getStudentByID(id: number) {
const endpoint = endpoints.students.retrieve.replace('{id}', id.toString());

axios.get(endpoint).then(response => {
student.value = Student.fromJSON(response.data);
}).catch(error => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we just discard errors, but there are several cases where we should handle these errors:

  • Network disconnects
  • Authorization errors
  • Not found errors
  • Other errors (custom validation errors, server errors)

One way to handle these is to define a new variable const errors = ref(null) and set its value when we catch an error. Components that use the composable services can watch this variable to display meaningful messages in case of an error.

We can also use PrimeVue's ToastService to automatically display a toast in the top right corner with the error messages (https://primevue.org/toast/).

Another thing: all data services will probably use the same structure (a single ref for a single data instance, one for a list, one for the errors). Maybe investigate how to abstract this so we don't have to repeat this in each service?

console.log(error.data);
});

console.log(student)
}

async function getStudents() {
const endpoint = endpoints.students.index;

axios.get(endpoint).then(response => {
students.value = response.data.map((studentData: Student) => Student.fromJSON(studentData));
}).catch(error => {
console.log(error.data);
});

console.log(students.value ? students.value.map((student, index) => `Student ${index + 1}: ${JSON.stringify(student)}`) : 'Students is null');
}

return {
students,
student,
getStudentByID,
getStudents
};
}
Loading
Loading