Skip to content

Commit

Permalink
chore: ComposerTranslation object gets passed through service functio…
Browse files Browse the repository at this point in the history
…ns part2 #149
  • Loading branch information
bsilkyn committed Mar 25, 2024
1 parent 916a4f1 commit 7e662cb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
15 changes: 8 additions & 7 deletions frontend/src/composables/services/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@ import axios from 'axios';
import { get, getList, getListMerged } from '@/composables/services/helpers.ts';
import { Course } from '@/types/Course';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";


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

async function getProjectByID(id: number) {
async function getProjectByID(id: number, t: ComposerTranslation) {
const endpoint = endpoints.projects.retrieve.replace('{id}', id.toString());
get<Project>(endpoint, project, Project.fromJSON, toast);
get<Project>(endpoint, project, Project.fromJSON, toast, t);
console.log(project)
}

async function getProjectsByCourse(course_id: number) {
async function getProjectsByCourse(course_id: number, t: ComposerTranslation) {
const endpoint = endpoints.projects.byCourse.replace('{course_id}', course_id.toString());
getList<Project>(endpoint, projects, Project.fromJSON, toast);
getList<Project>(endpoint, projects, Project.fromJSON, toast, t);
console.log(projects.value ? projects.value.map((project, index) => `Project ${index + 1}: ${JSON.stringify(project)}`) : 'Projects is null');
}

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

const endpList = [];
for (const course of courses.value?courses.value:[]){
endpList.push(endpoints.projects.byCourse.replace('{course_id}', course.id.toString()));
}
await getListMerged<Project>(endpList, projects, Project.fromJSON, toast);
await getListMerged<Project>(endpList, projects, Project.fromJSON, toast, t);
console.log(projects.value ? projects.value.map((project, index) => `Project ${index + 1}: ${JSON.stringify(project)}`) : 'Projects is null');
}

Expand Down
9 changes: 5 additions & 4 deletions frontend/src/composables/services/structure_check.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

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

async function getStructure_checkByID(id: number) {
async function getStructure_checkByID(id: number, t: ComposerTranslation) {
const endpoint = endpoints.structure_checks.retrieve.replace('{id}', id.toString());
get<Structure_check>(endpoint, structure_check, Structure_check.fromJSON, toast);
get<Structure_check>(endpoint, structure_check, Structure_check.fromJSON, toast, t);
console.log(structure_check)
}

async function getStructure_checkByProject(project_id: number) {
async function getStructure_checkByProject(project_id: number, t: ComposerTranslation) {
const endpoint = endpoints.structure_checks.byProject.replace('{project_id}', project_id.toString());
getList<Structure_check>(endpoint, structure_checks, Structure_check.fromJSON, toast);
getList<Structure_check>(endpoint, structure_checks, Structure_check.fromJSON, toast, t);
console.log(structure_checks.value ? structure_checks.value.map((structure_check, index) => `Structure_check ${index + 1}: ${JSON.stringify(structure_check)}`) : 'Structure_check is null');
}

Expand Down
9 changes: 5 additions & 4 deletions frontend/src/composables/services/students.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

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

async function getStudentByID(id: number) {
async function getStudentByID(id: number, t: ComposerTranslation) {
const endpoint = endpoints.students.retrieve.replace('{id}', id.toString());
get<Student>(endpoint, student, Student.fromJSON, toast);
get<Student>(endpoint, student, Student.fromJSON, toast, t);
console.log(student)
}

async function getStudents() {
async function getStudents(t: ComposerTranslation) {
const endpoint = endpoints.students.index;
getList<Student>(endpoint, students, Student.fromJSON, toast);
getList<Student>(endpoint, students, Student.fromJSON, toast, t);
console.log(students.value ? students.value.map((student, index) => `Student ${index + 1}: ${JSON.stringify(student)}`) : 'Students is null');
}

Expand Down
13 changes: 7 additions & 6 deletions frontend/src/composables/services/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useSubmission() {
const submissions = ref<Submission[]|null>(null);
const submission = ref<Submission|null>(null);
const toast = useToast();

async function getSubmissionByID(id: number) {
async function getSubmissionByID(id: number, t: ComposerTranslation) {
const endpoint = endpoints.submissions.retrieve.replace('{id}', id.toString());
get<Submission>(endpoint, submission, Submission.fromJSON, toast);
get<Submission>(endpoint, submission, Submission.fromJSON, toast, t);
console.log(submission)
}

async function getSubmissionByProject(project_id: number) {
async function getSubmissionByProject(project_id: number, t: ComposerTranslation) {
const endpoint = endpoints.submissions.byProject.replace('{project_id}', project_id.toString());
getList<Submission>(endpoint, submissions, Submission.fromJSON, toast);
getList<Submission>(endpoint, submissions, Submission.fromJSON, toast, t);
console.log(submissions.value ? submissions.value.map((submission, index) => `Submission ${index + 1}: ${JSON.stringify(submission)}`) : 'Submission is null');
}

async function getSubmissionByGroup(group_id: number) {
async function getSubmissionByGroup(group_id: number, t: ComposerTranslation) {
const endpoint = endpoints.submissions.byGroup.replace('{group_id}', group_id.toString());
getList<Submission>(endpoint, submissions, Submission.fromJSON, toast);
getList<Submission>(endpoint, submissions, Submission.fromJSON, toast, t);
console.log(submissions.value ? submissions.value.map((submission, index) => `Submission ${index + 1}: ${JSON.stringify(submission)}`) : 'Submission is null');
}

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/composables/services/submissionStatus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import {endpoints} from '@/config/endpoints.ts';
import { get} from '@/composables/services/helpers.ts';
import { SubmissionStatus } from '@/types/SubmisionStatus';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useSubmission() {
const submissionStatus = ref<SubmissionStatus|null>(null);
const toast = useToast();

async function getSubmissionStatus(project_id: number) {
async function getSubmissionStatus(project_id: number, t: ComposerTranslation) {
const endpoint = endpoints.submissions.status.replace('{project_id}', project_id.toString());
get<SubmissionStatus>(endpoint, submissionStatus, SubmissionStatus.fromJSON, toast);
get<SubmissionStatus>(endpoint, submissionStatus, SubmissionStatus.fromJSON, toast, t);
console.log(submissionStatus)
}

Expand Down
9 changes: 5 additions & 4 deletions frontend/src/composables/services/teachers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import {ref} from 'vue';
import {endpoints} from '@/config/endpoints.ts';
import { get, getList } from '@/composables/services/helpers.ts';
import { useToast } from 'primevue/usetoast';
import {ComposerTranslation} from "vue-i18n";

export function useTeacher() {
const teachers = ref<Teacher[]|null>(null);
const teacher = ref<Teacher|null>(null);
const toast = useToast();

async function getTeacherByID(id: number) {
async function getTeacherByID(id: number, t: ComposerTranslation) {
const endpoint = endpoints.teachers.retrieve.replace('{id}', id.toString());
get<Teacher>(endpoint, teacher, Teacher.fromJSON, toast);
get<Teacher>(endpoint, teacher, Teacher.fromJSON, toast, t);
console.log(teacher)
}

async function getTeachers() {
async function getTeachers(t: ComposerTranslation) {
const endpoint = endpoints.teachers.index;
getList<Teacher>(endpoint, teachers, Teacher.fromJSON, toast);
getList<Teacher>(endpoint, teachers, Teacher.fromJSON, toast, t);
console.log(teachers.value ? teachers.value.map((teacher, index) => `Teacher ${index + 1}: ${JSON.stringify(teacher)}`) : 'Teachers is null');
}

Expand Down

0 comments on commit 7e662cb

Please sign in to comment.