Spaces:
Running

File size: 7,832 Bytes
a1867e5
0d24759
a1867e5
0d24759
a1867e5
64051e5
a1867e5
 
 
 
 
 
 
 
64051e5
 
a1867e5
64051e5
 
 
a1867e5
64051e5
a1867e5
64051e5
a1867e5
 
 
64051e5
 
a1867e5
 
64051e5
 
a1867e5
64051e5
 
a1867e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64051e5
 
 
a1867e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d24759
 
 
a1867e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d24759
 
 
 
a1867e5
 
 
64051e5
 
a1867e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64051e5
 
 
a1867e5
64051e5
a1867e5
64051e5
a1867e5
 
 
 
 
64051e5
 
a1867e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64051e5
 
 
a1867e5
 
 
64051e5
 
a1867e5
 
 
 
 
 
 
 
 
64051e5
 
a1867e5
0d24759
 
a1867e5
 
 
0d24759
 
 
a1867e5
 
 
0d24759
 
a1867e5
 
 
 
 
0d24759
 
 
a1867e5
64051e5
a1867e5
64051e5
a1867e5
 
 
64051e5
a1867e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64051e5
 
a1867e5
 
 
ec8a701
a1867e5
 
 
ec8a701
 
a1867e5
 
ec8a701
 
 
a1867e5
ec8a701
a1867e5
ec8a701
a1867e5
 
 
ec8a701
a1867e5
 
 
 
 
 
 
 
 
 
 
ec8a701
 
a1867e5
64051e5
a1867e5
0d24759
a1867e5
 
 
0d24759
 
a1867e5
 
0d24759
 
a1867e5
64051e5
 
a1867e5
 
 
 
 
 
 
 
 
 
64051e5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# MeloonExam RESTful API 接口规范文档

---

## 1. 全局约定与服务基础

- **基础路径**:`/api`
- **协议格式**:`application/json; charset=utf-8`
- **本地服务地址**:
  - 前端服务(带 Express 代理):`http://localhost:3001`
  - 直连后端服务:`http://127.0.0.1:8000`
- **身份认证规范**:
  - HTTP 请求头携带 `Authorization: Bearer <token>` 或 `X-User-Id: <user_id>`。
- **通用错误响应**:
```json
{
  "detail": "错误信息描述"
}
```

---

## 2. 通行证认证接口 (`/api/exam/auth` 与 `/api/auth`)

### 2.1 用户登录
- **端点**:`POST /api/exam/auth/login` 或 `POST /api/auth/login`
- **请求体**:
```json
{
  "identifier": "student_li", // 支持用户名或邮箱
  "password": "Password123!"
}
```
- **成功响应 (200 OK)**:
```json
{
  "success": true,
  "user": {
    "id": "7a3556bf-9c76-4d57-9db0-5e58ce245b0a",
    "username": "student_li",
    "email": "student_li@meloon.edu.cn",
    "nickname": "李小华 同学",
    "avatar_url": "https://api.dicebear.com/7.x/adventurer/svg?seed=li",
    "role": "student"
  },
  "profile": {
    "school": "北京四中",
    "grade": "高三",
    "stage": "gaokao",
    "selected_subjects": ["chinese", "math", "english", "physics", "chemistry", "biology"],
    "subject_expectations": { "math": 140, "physics": 95 },
    "subject_scores": { "math": 132, "physics": 88 }
  },
  "access_token": "eyJhbGciOiJIUzI1NiIsIn...",
  "token_type": "bearer",
  "message": "登录成功!"
}
```

---

## 3. 试卷题库核心接口 (`/api/papers`)

### 3.1 检索与筛选试卷
- **端点**:`GET /api/papers/`
- **查询参数**:
  - `stage` (string, 可选): `gaokao` | `zhongkao`
  - `subject` (string, 可选): `math` | `physics` | `chemistry` 等
  - `year` (int, 可选): 年份如 `2025`
  - `province` (string, 可选): 省份如 `新高考I卷`
  - `category` (string, 可选): `真题` | `一模` | `名校联考`
  - `difficulty` (int, 可选): 1-5
  - `page` (int, 默认 1): 当前页
  - `limit` (int, 默认 20): 每页条数
- **成功响应 (200 OK)**:
```json
[
  {
    "id": "paper-user-1788592348590",
    "title": "2025年普通高等学校招生全国统一考试·数学(新高考I卷)",
    "stage": "gaokao",
    "subject": "math",
    "year": 2025,
    "province": "新高考I卷",
    "city": "全国通用",
    "school": "教育部教育考试院",
    "category": "真题",
    "full_score": 150,
    "time_minutes": 120,
    "difficulty": 4,
    "tags": ["高考真题", "解析全面", "新结构试卷"],
    "download_count": 8920,
    "view_count": 35400,
    "like_count": 1420,
    "has_answer": true,
    "has_analysis": true,
    "is_featured": true,
    "created_at": "2025-06-08T18:00:00Z"
  }
]
```

### 3.2 获取试卷详情 (含全卷试题与 LaTeX 解析)
- **端点**:`GET /api/papers/{id}`
- **成功响应 (200 OK)**:
```json
{
  "id": "paper-user-1788592348590",
  "title": "2025年全国统一高考数学真题 (新高考I卷)",
  "full_score": 150,
  "questions": [
    {
      "id": "q-1",
      "number": 1,
      "type": "single_choice",
      "score": 5,
      "stem": "设集合 $A = \\{x \\mid -1 < x < 2\\}$,$B = \\{x \\mid x^2 - 4x + 3 < 0\\}$,则 $A \\cap B = ()$",
      "options": [
        "$(1, 2)$",
        "$(-1, 3)$",
        "$(1, 3)$",
        "$(-1, 2)$"
      ],
      "answer": "A",
      "analysis": "由题意得 $B = (1, 3)$,又 $A = (-1, 2)$,所以 $A \\cap B = (1, 2)$。故选 A。",
      "knowledge_points": ["集合的交集运算", "一元二次不等式解法"]
    }
  ]
}
```

---

## 4. 考试历史成绩中心 (`/api/users/me/score-history`)

### 4.1 查询当前用户历史成绩
- **端点**:`GET /api/users/me/score-history`
- **查询参数**:
  - `subject` (string, 可选): 筛选特定科目(如 `math`)
- **成功响应 (200 OK)**:
```json
{
  "success": true,
  "count": 2,
  "records": [
    {
      "id": "4b68e922-a74f-4d38-9642-1e9bf1f4e156",
      "user_id": "7a3556bf-9c76-4d57-9db0-5e58ce245b0a",
      "exam_name": "2026届高三海淀零模统一测验",
      "exam_date": "2026-03-15",
      "stage": "gaokao",
      "subject": "math",
      "score": 136.5,
      "full_score": 150.0,
      "rank": 42,
      "percentile": 96.8,
      "notes": "导数第二小问分类讨论有漏洞,立体几何建系计算准确无误。",
      "created_at": "2026-03-16T09:00:00Z"
    }
  ]
}
```

### 4.2 录入一条历史考试成绩
- **端点**:`POST /api/users/me/score-history`
- **请求体**:
```json
{
  "exam_name": "2026届高三海淀一模统一测验",
  "exam_date": "2026-04-10",
  "stage": "gaokao",
  "subject": "math",
  "score": 141.0,
  "full_score": 150.0,
  "rank": 18,
  "percentile": 98.6,
  "notes": "解析几何设线计算大幅提速,整体发挥稳健。"
}
```
- **成功响应 (200 OK)**:
```json
{
  "success": true,
  "message": "历史成绩已成功写入数据库表 exam_score_history",
  "id": "5f190e33-7281-4ba2-b258-a832c3f8e910"
}
```

### 4.3 批量导入或更新成绩
- **端点**:`POST /api/users/me/score-history/batch`
- **请求体**:
```json
{
  "replaceExisting": false,
  "records": [
    { "exam_name": "期末考", "subject": "chinese", "score": 118, "full_score": 150 },
    { "exam_name": "期末考", "subject": "english", "score": 135, "full_score": 150 }
  ]
}
```

---

## 5. 智能错题本接口 (`/api/users/me/mistakes`)

### 5.1 获取错题列表
- **端点**:`GET /api/users/me/mistakes`
- **成功响应 (200 OK)**:
```json
[
  {
    "id": "mstk-1721000000000",
    "question_id": "q-12",
    "paper_id": "paper-user-1788592348590",
    "paper_title": "2025年全国统一高考数学真题 (新高考I卷)",
    "subject": "math",
    "stem": "已知椭圆 $C: \\frac{x^2}{a^2} + \\frac{y^2}{b^2} = 1$ 的离心率为 $\\frac{\\sqrt{2}}{2}$...",
    "answer": "$\\frac{x^2}{2} + y^2 = 1$",
    "analysis": "联立直线与椭圆方程,利用韦达定理消元...",
    "user_note": "考试时未考虑直线斜率不存在的边界情况,导致被扣 4 分。",
    "is_mastered": false,
    "wrong_count": 2
  }
]
```

### 5.2 添加错题
- **端点**:`POST /api/users/me/mistakes`
- **请求体**:接收错题对象字段,返回新增的错题实体。

### 5.3 标记掌握状态与更新心得
- **端点**:`PUT /api/users/me/mistakes/{id}`
- **请求体**:
```json
{
  "is_mastered": true,
  "user_note": "已彻底吃透斜率不存在讨论与点差法变式。"
}
```

---

## 6. 考试日历接口 (`/api/exam-events`)

### 6.1 获取考试日程与节点
- **端点**:`GET /api/exam-events`
- **成功响应 (200 OK)**:
```json
[
  {
    "id": "event-gaokao-2026",
    "title": "2026年全国统一高考",
    "event_date": "2026-06-07",
    "stage": "gaokao",
    "category": "national_exam",
    "description": "全国普通高等学校统一招生考试首日(语文、数学)",
    "days_remaining": 248
  }
]
```

---

## 7. AI 智能解题接口 (`/api/ai`)

### 7.1 请求 AI 推导题目解析
- **端点**:`POST /api/ai/solve`
- **请求体**:
```json
{
  "question_stem": "已知函数 $f(x) = e^x - ax - 1$ 在 $\\mathbb{R}$ 上恒有 $f(x) \\ge 0$,求实数 $a$ 的取值集合。",
  "subject": "math"
}
```
- **成功响应 (200 OK)**:
```json
{
  "success": true,
  "result": {
    "final_answer": "$a = 1$",
    "steps": [
      { "step": 1, "title": "求导分析极值", "content": "求导得 $f'(x) = e^x - a$..." },
      { "step": 2, "title": "分类讨论参数", "content": "若 $a \\le 0$,易得矛盾;若 $a > 0$..." }
    ],
    "key_formulas": ["$e^x \\ge x + 1$ (切线放缩不等式)"],
    "common_mistakes": ["容易遗漏 $a \\le 0$ 时函数单调递增导致取负值的边界检验。"]
  }
}
```