Initial commit: secondary school grade archive system.

Add FastAPI/React app with Docker deployment, Ubuntu one-click install, and docs for junior/senior high score tracking and mistake bank.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-28 11:18:58 +08:00
commit e329d3398a
76 changed files with 8506 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
import axios from 'axios'
import type {
Exam,
ScoreInput,
SchoolLevel,
Student,
Subject,
TokenResponse,
TrendResponse,
User,
WrongQuestion,
} from '../types'
import type { ExamType } from '../types'
const api = axios.create({
baseURL: '/api',
})
api.interceptors.request.use((config) => {
const token = localStorage.getItem('access_token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
api.interceptors.response.use(
(res) => res,
async (error) => {
const original = error.config
if (error.response?.status === 401 && !original._retry) {
original._retry = true
const refresh = localStorage.getItem('refresh_token')
if (refresh) {
try {
const { data } = await axios.post<TokenResponse>('/api/auth/refresh', {
refresh_token: refresh,
})
localStorage.setItem('access_token', data.access_token)
localStorage.setItem('refresh_token', data.refresh_token)
original.headers.Authorization = `Bearer ${data.access_token}`
return api(original)
} catch {
localStorage.removeItem('access_token')
localStorage.removeItem('refresh_token')
window.location.href = '/login'
}
}
}
return Promise.reject(error)
},
)
export const authApi = {
register: (username: string, password: string) =>
api.post<User>('/auth/register', { username, password }),
login: (username: string, password: string) =>
api.post<TokenResponse>('/auth/login', { username, password }),
me: () => api.get<User>('/auth/me'),
}
export const studentApi = {
list: () => api.get<Student[]>('/students'),
create: (data: {
name: string
school_level?: SchoolLevel
grade?: string
class_name?: string
}) => api.post<Student>('/students', data),
get: (id: string) => api.get<Student>(`/students/${id}`),
update: (id: string, data: Partial<Student>) => api.patch<Student>(`/students/${id}`, data),
remove: (id: string) => api.delete(`/students/${id}`),
}
export const subjectApi = {
list: () => api.get<Subject[]>('/subjects'),
}
export const examApi = {
list: (studentId: string) => api.get<Exam[]>(`/students/${studentId}/exams`),
create: (
studentId: string,
data: { exam_type: ExamType; exam_date: string; title?: string; scores: ScoreInput[] },
) => api.post<Exam>(`/students/${studentId}/exams`, data),
update: (
examId: string,
data: Partial<{ exam_type: ExamType; exam_date: string; title: string; scores: ScoreInput[] }>,
) => api.patch<Exam>(`/exams/${examId}`, data),
remove: (examId: string) => api.delete(`/exams/${examId}`),
trend: (studentId: string, subjectId: number) =>
api.get<TrendResponse>(`/students/${studentId}/scores/trend`, {
params: { subject_id: subjectId },
}),
exportCsv: (studentId: string) =>
api.get(`/students/${studentId}/scores/export`, { responseType: 'blob' }),
}
export const wrongQuestionApi = {
list: (studentId: string, params?: { subject_id?: number; q?: string }) =>
api.get<WrongQuestion[]>(`/students/${studentId}/wrong-questions`, { params }),
upload: (studentId: string, subjectId: number, file: File) => {
const form = new FormData()
form.append('subject_id', String(subjectId))
form.append('file', file)
return api.post<WrongQuestion>(`/students/${studentId}/wrong-questions`, form)
},
get: (id: string) => api.get<WrongQuestion>(`/wrong-questions/${id}`),
update: (id: string, data: Partial<WrongQuestion>) =>
api.patch<WrongQuestion>(`/wrong-questions/${id}`, data),
remove: (id: string) => api.delete(`/wrong-questions/${id}`),
retryOcr: (id: string) => api.post<WrongQuestion>(`/wrong-questions/${id}/retry-ocr`),
regenerate: (id: string) =>
api.post<WrongQuestion>(`/wrong-questions/${id}/regenerate-solution`),
imageUrl: (id: string) => `/api/wrong-questions/${id}/image`,
}
export default api