- Backend: AI generation fallbacks when OpenAI not configured, full exam submission saving all params (difficulty, rubric, entity, grading system, approval workflow) and creating linked question records per section - Backend: new exam session controller with get_session, autosave, submit, status, and results endpoints; student attempt/answer/score models - Backend: new controllers for entities, approval workflows, exam schedules - Frontend: exam session split-layout with passage panel, question types (MCQ, T/F/NG, gap-fill, writing, speaking), timer, and review dialog - Frontend: results page with percentage score, per-answer breakdown table - Frontend: generation page dynamic dropdowns, full payload submission - Frontend: updated types for ExamSessionSection, ExamQuestion options Made-with: Cursor
96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
import { api } from "@/lib/api-client";
|
|
import type { Exam, ExamModule, Rubric, RubricGroup, ExamStructure, PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";
|
|
|
|
export interface ExamListParams extends PaginationParams {
|
|
module?: ExamModule;
|
|
subject_id?: number;
|
|
entity_id?: number;
|
|
}
|
|
|
|
export const examsService = {
|
|
async list(module: ExamModule, params?: PaginationParams): Promise<PaginatedResponse<Exam>> {
|
|
return api.get<PaginatedResponse<Exam>>(`/exam/${module}`, params as Record<string, string | number | boolean | undefined>);
|
|
},
|
|
|
|
async getById(module: ExamModule, id: number): Promise<Exam> {
|
|
return api.get<Exam>(`/exam/${module}/${id}`);
|
|
},
|
|
|
|
async create(data: Partial<Exam>): Promise<Exam> {
|
|
return api.post<Exam>("/exam", data);
|
|
},
|
|
|
|
async update(id: number, data: Partial<Exam>): Promise<Exam> {
|
|
return api.patch<Exam>(`/exam/${id}`, data);
|
|
},
|
|
|
|
async delete(id: number): Promise<ApiSuccessResponse> {
|
|
return api.delete<ApiSuccessResponse>(`/exam/${id}`);
|
|
},
|
|
|
|
async setAccess(id: number, access: "public" | "private"): Promise<Exam> {
|
|
return api.patch<Exam>(`/exam/${id}/access`, { access });
|
|
},
|
|
|
|
async listRubrics(params?: PaginationParams): Promise<PaginatedResponse<Rubric>> {
|
|
return api.get<PaginatedResponse<Rubric>>("/rubrics", params as Record<string, string | number | boolean | undefined>);
|
|
},
|
|
|
|
async createRubric(data: Partial<Rubric>): Promise<Rubric> {
|
|
return api.post<Rubric>("/rubrics", data);
|
|
},
|
|
|
|
async updateRubric(id: number, data: Partial<Rubric>): Promise<Rubric> {
|
|
return api.put<Rubric>(`/rubrics/${id}`, data);
|
|
},
|
|
|
|
async deleteRubric(id: number): Promise<ApiSuccessResponse> {
|
|
return api.delete<ApiSuccessResponse>(`/rubrics/${id}`);
|
|
},
|
|
|
|
async listRubricGroups(params?: PaginationParams): Promise<PaginatedResponse<RubricGroup>> {
|
|
return api.get<PaginatedResponse<RubricGroup>>("/rubric-groups", params as Record<string, string | number | boolean | undefined>);
|
|
},
|
|
|
|
async createRubricGroup(data: { name: string; rubric_ids: number[] }): Promise<RubricGroup> {
|
|
return api.post<RubricGroup>("/rubric-groups", data);
|
|
},
|
|
|
|
async updateRubricGroup(id: number, data: { name?: string; rubric_ids?: number[] }): Promise<RubricGroup> {
|
|
return api.put<RubricGroup>(`/rubric-groups/${id}`, data);
|
|
},
|
|
|
|
async deleteRubricGroup(id: number): Promise<ApiSuccessResponse> {
|
|
return api.delete<ApiSuccessResponse>(`/rubric-groups/${id}`);
|
|
},
|
|
|
|
async listStructures(params?: PaginationParams & { entity_id?: number }): Promise<PaginatedResponse<ExamStructure>> {
|
|
return api.get<PaginatedResponse<ExamStructure>>("/exam-structures", params as Record<string, string | number | boolean | undefined>);
|
|
},
|
|
|
|
async createStructure(data: Partial<ExamStructure>): Promise<ExamStructure> {
|
|
return api.post<ExamStructure>("/exam-structures", data);
|
|
},
|
|
|
|
async updateStructure(id: number, data: Partial<ExamStructure>): Promise<ExamStructure> {
|
|
return api.put<ExamStructure>(`/exam-structures/${id}`, data);
|
|
},
|
|
|
|
async deleteStructure(id: number): Promise<ApiSuccessResponse> {
|
|
return api.delete<ApiSuccessResponse>(`/exam-structures/${id}`);
|
|
},
|
|
|
|
async suggestRubricCriteria(data: {
|
|
name?: string;
|
|
skill: string;
|
|
exam_type: string;
|
|
levels: string[];
|
|
}): Promise<{ criteria: string[]; suggested_levels?: string[] }> {
|
|
return api.post("/ai/suggest-rubric-criteria", data);
|
|
},
|
|
|
|
async getAvatars(): Promise<{ id: number; name: string; thumbnail: string }[]> {
|
|
return api.get("/exam/avatars");
|
|
},
|
|
};
|