fix: merge + types frontend controller

This commit is contained in:
Gabriellvl 2025-04-02 12:21:04 +02:00
parent 4ca568e738
commit 8ceed7f779
20 changed files with 129 additions and 92 deletions

View file

@ -0,0 +1,3 @@
import type {AssignmentDTO} from "dwengo-1-common/src/interfaces/assignment";
export type AssignmentsResponse = { assignments: AssignmentDTO[] }; // TODO ID

View file

@ -0,0 +1,3 @@
import type {ClassDTO} from "dwengo-1-common/src/interfaces/class";
export type ClassesResponse = { classes: ClassDTO[] | string[] };

View file

@ -0,0 +1,3 @@
import type {GroupDTO} from "dwengo-1-common/src/interfaces/group";
export type GroupsResponse = { groups: GroupDTO[] }; // | TODO id

View file

@ -0,0 +1,3 @@
import type {QuestionDTO, QuestionId} from "dwengo-1-common/src/interfaces/question";
export type QuestionsResponse = { questions: QuestionDTO[] | QuestionId[] }

View file

@ -1,59 +1,72 @@
import { BaseController } from "@/controllers/base-controller.ts";
import type {StudentDTO} from "dwengo-1-common/src/interfaces/student";
import type {ClassesResponse} from "@/controllers/classes.ts";
import type {AssignmentsResponse} from "@/controllers/assignments.ts";
import type {GroupsResponse} from "@/controllers/groups.ts";
import type {SubmissionsResponse} from "@/controllers/submissions.ts";
import type {QuestionsResponse} from "@/controllers/questions.ts";
import type {ClassJoinRequestDTO} from "dwengo-1-common/src/interfaces/class-join-request";
export type StudentsResponse = { students: StudentDTO[] | string[] };
export type StudentResponse = { student: StudentDTO };
export type JoinRequestsResponse = { requests: ClassJoinRequestDTO[] };
export type JoinRequestResponse = { request: ClassJoinRequestDTO };
export class StudentController extends BaseController {
constructor() {
super("student");
}
getAll(full = true) {
return this.get<{ students: any[] }>("/", { full });
async getAll(full = true): Promise<StudentsResponse> {
return this.get<StudentsResponse>("/", { full });
}
getByUsername(username: string) {
return this.get<{ student: any }>(`/${username}`);
async getByUsername(username: string): Promise<StudentResponse> {
return this.get<StudentResponse>(`/${username}`);
}
createStudent(data: any) {
return this.post("/", data);
async createStudent(data: StudentDTO): Promise<StudentResponse> {
return this.post<StudentResponse>("/", data);
}
deleteStudent(username: string) {
return this.delete(`/${username}`);
async deleteStudent(username: string): Promise<StudentResponse> {
return this.delete<StudentResponse>(`/${username}`);
}
getClasses(username: string, full = true) {
return this.get<{ classes: any[] }>(`/${username}/classes`, { full });
async getClasses(username: string, full = true): Promise<ClassesResponse> {
return this.get<ClassesResponse>(`/${username}/classes`, { full });
}
getAssignments(username: string, full = true) {
return this.get<{ assignments: any[] }>(`/${username}/assignments`, { full });
async getAssignments(username: string, full = true): Promise<AssignmentsResponse> {
return this.get<AssignmentsResponse>(`/${username}/assignments`, { full });
}
getGroups(username: string, full = true) {
return this.get<{ groups: any[] }>(`/${username}/groups`, { full });
async getGroups(username: string, full = true): Promise<GroupsResponse> {
return this.get<GroupsResponse>(`/${username}/groups`, { full });
}
getSubmissions(username: string) {
return this.get<{ submissions: any[] }>(`/${username}/submissions`);
async getSubmissions(username: string): Promise<SubmissionsResponse> {
return this.get<SubmissionsResponse>(`/${username}/submissions`);
}
getQuestions(username: string, full = true) {
return this.get<{ questions: any[] }>(`/${username}/questions`, { full });
async getQuestions(username: string, full = true): Promise<QuestionsResponse> {
return this.get<QuestionsResponse>(`/${username}/questions`, { full });
}
getJoinRequests(username: string) {
return this.get<{ requests: any[] }>(`/${username}/joinRequests`);
async getJoinRequests(username: string): Promise<JoinRequestsResponse> {
return this.get<JoinRequestsResponse>(`/${username}/joinRequests`);
}
getJoinRequest(username: string, classId: string) {
return this.get<{ request: any[] }>(`/${username}/joinRequests/${classId}`);
async getJoinRequest(username: string, classId: string): Promise<JoinRequestResponse> {
return this.get<JoinRequestResponse>(`/${username}/joinRequests/${classId}`);
}
createJoinRequest(username: string, classId: string) {
return this.post(`/${username}/joinRequests}`, classId);
async createJoinRequest(username: string, classId: string): Promise<JoinRequestResponse> {
return this.post<JoinRequestResponse>(`/${username}/joinRequests}`, classId);
}
deleteJoinRequest(username: string, classId: string) {
return this.delete(`/${username}/joinRequests/${classId}`);
async deleteJoinRequest(username: string, classId: string): Promise<JoinRequestResponse> {
return this.delete<JoinRequestResponse>(`/${username}/joinRequests/${classId}`);
}
}

View file

@ -0,0 +1,3 @@
import {type SubmissionDTO, SubmissionDTOId} from "dwengo-1-common/src/interfaces/submission";
export type SubmissionsResponse = { submissions: SubmissionDTO[] | SubmissionDTOId[] };

View file

@ -1,44 +1,52 @@
import { BaseController } from "@/controllers/base-controller.ts";
import type {JoinRequestResponse, JoinRequestsResponse, StudentsResponse} from "@/controllers/students.ts";
import type {QuestionsResponse} from "@/controllers/questions.ts";
import type {ClassesResponse} from "@/controllers/classes.ts";
import type {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher";
export type TeachersResponse = { teachers: TeacherDTO[] | string[] };
export type TeacherResponse = { teacher: TeacherDTO | string };
export class TeacherController extends BaseController {
constructor() {
super("teacher");
}
getAll(full = false) {
return this.get<{ teachers: any[] }>("/", { full });
async getAll(full = false): Promise<TeachersResponse> {
return this.get<TeachersResponse>("/", { full });
}
getByUsername(username: string) {
return this.get<any>(`/${username}`);
async getByUsername(username: string): Promise<TeacherResponse> {
return this.get<TeacherResponse>(`/${username}`);
}
createTeacher(data: any) {
return this.post("/", data);
async createTeacher(data: any): Promise<TeacherResponse> {
return this.post<TeacherResponse>("/", data);
}
deleteTeacher(username: string) {
return this.delete(`/${username}`);
async deleteTeacher(username: string): Promise<TeacherResponse> {
return this.delete<TeacherResponse>(`/${username}`);
}
getClasses(username: string, full = false) {
return this.get<any[]>(`/${username}/classes`, { full });
async getClasses(username: string, full = false): Promise<ClassesResponse> {
return this.get<ClassesResponse>(`/${username}/classes`, { full });
}
getStudents(username: string, full = false) {
return this.get<{ students: any[] }>(`/${username}/students`, { full });
async getStudents(username: string, full = false): Promise<StudentsResponse> {
return this.get<StudentsResponse>(`/${username}/students`, { full });
}
getQuestions(username: string, full = false) {
return this.get<{ questions: any[] }>(`/${username}/questions`, { full });
async getQuestions(username: string, full = false): Promise<QuestionsResponse> {
return this.get<QuestionsResponse>(`/${username}/questions`, { full });
}
getStudentJoinRequests(username: string, classId: string) {
return this.get<{ joinRequests: any[] }>(`/${username}/joinRequests/${classId}`);
async getStudentJoinRequests(username: string, classId: string): Promise<JoinRequestsResponse> {
return this.get<JoinRequestsResponse>(`/${username}/joinRequests/${classId}`);
}
updateStudentJoinRequest(teacherUsername: string, classId: string, studentUsername: string, accepted: boolean) {
return this.put(`/${teacherUsername}/joinRequests/${classId}/${studentUsername}`, accepted);
async updateStudentJoinRequest(teacherUsername: string, classId: string, studentUsername: string, accepted: boolean): Promise<JoinRequestResponse> {
return this.put<JoinRequestResponse>(`/${teacherUsername}/joinRequests/${classId}/${studentUsername}`, accepted);
}
// GetInvitations(id: string) {return this.get<{ invitations: string[] }>(`/${id}/invitations`);}