Spaces:
Running

isold's picture
update
a1867e5
|
Raw History Blame Contribute Delete
7.83 kB
# 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$ 时函数单调递增导致取负值的边界检验。"]
}
}
```