-
Notifications
You must be signed in to change notification settings - Fork 0
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
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 636bc90
chore: add faculty and teacher services
tyboro2002 4efcda8
Merge branch 'development' of https://github.com/SELab-2/UGent-7 into…
tyboro2002 da3b996
chore:completed teacher service scaffolding
tyboro2002 4b8df18
chore:completed teacher service scaffolding
tyboro2002 ada1663
chore: added admin service and fixed some things in teacher and stude…
tyboro2002 1bb063f
chore: add assistant service
tyboro2002 65cd4f6
chore: testing if courses service works + adding all course service
tyboro2002 25cf971
Merge branch 'services' of https://github.com/SELab-2/UGent-7 into se…
tyboro2002 944222b
chore: make dashboard display courses from api
tyboro2002 12bc8de
chore: add project type
tyboro2002 0377726
chore: add project service
tyboro2002 61f1151
chore: add submision service
tyboro2002 bb5478d
chore: add structure_check service
tyboro2002 5b101d6
chore: add all admins service
tyboro2002 fe6368b
chore: add all assistants service
tyboro2002 e8ba1a9
chore: add all assistants service
tyboro2002 d69d6eb
chore: add all teachers service
tyboro2002 e114d4e
chore: add all facultys service
tyboro2002 5561720
chore: add projects by date course service
tyboro2002 59d9095
fix: fix comments of bram
tyboro2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -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 | ||
}; | ||
} |
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 |
---|---|---|
@@ -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 | ||
}; | ||
} |
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 |
---|---|---|
@@ -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 | ||
}; | ||
} |
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 |
---|---|---|
@@ -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 | ||
}; | ||
} |
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 |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
*/ |
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 |
---|---|---|
@@ -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
40
frontend/src/composables/services/structure_check.service.ts
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 |
---|---|---|
@@ -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 | ||
}; | ||
} |
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 |
---|---|---|
@@ -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 => { | ||
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 | ||
}; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
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?