2024/8/1 13:32:45 ![]()
请根据上面的全部api编写对应的API说明文档。需要有详细的使用方法、说明、举例等信息。
2024/8/1 13:32:45 
### 教学管理系统 API 说明文档
#### 概述本API提供对教学管理系统中用户管理、班级管理、步程管理、视频管理、测试题管理和用户评论等功能的访问和操作。所有API均采用RESTful风格。
### 基本信息
- Base URL: `http://yourdomain.com/api`
- 所有请求均应包含以下HTTP头信息: - `Content-Type: application/json` - `Accept: application/json`
### API 目录
1. [用户管理](#用户管理)2. [班级管理](#班级管理)3. [步程管理](#步程管理)4. [视频管理](#视频管理)5. [测试题管理](#测试题管理)6. [用户评论](#用户评论)
### 用户管理
#### 获取所有用户
- **URL**: `/users`- **方法**: `GET`- **说明**: 获取系统中所有用户的列表。- **请求参数**: 无- **示例请求**: ```bash curl -X GET http://yourdomain.com/api/users ```- **响应**: ```json [ { "user_id": 1, "username": "admin", "email": "admin@example.com", "role": "admin", "avatar": "avatar1.png" }, { "user_id": 2, "username": "teacher1", "email": "teacher1@example.com", "role": "teacher", "avatar": "avatar2.png" }, ... ] ```
#### 创建用户
- **URL**: `/users`- **方法**: `POST`- **说明**: 创建一个新的用户。- **请求参数**: - `username` (string): 用户名 - `password` (string): 密码 - `email` (string): 邮箱 - `role` (string): 角色(admin/teacher/student) - `avatar` (string): 头像URL- **示例请求**: ```bash curl -X POST http://yourdomain.com/api/users -d '{ "username": "newuser", "password": "password123", "email": "newuser@example.com", "role": "student", "avatar": "avatar.png" }' ```- **响应**: ```json { "message": "User was created." } ```
### 班级管理
#### 获取所有班级
- **URL**: `/classes`- **方法**: `GET`- **说明**: 获取系统中所有班级的列表。- **请求参数**: 无- **示例请求**: ```bash curl -X GET http://yourdomain.com/api/classes ```- **响应**: ```json [ { "class_id": 1, "class_name": "Math 101", "description": "Basic Math Class", "semester": "Fall 2023" }, { "class_id": 2, "class_name": "Physics 101", "description": "Basic Physics Class", "semester": "Fall 2023" }, ... ] ```
#### 创建班级
- **URL**: `/classes`- **方法**: `POST`- **说明**: 创建一个新的班级。- **请求参数**: - `class_name` (string): 班级名称 - `description` (string): 描述 - `semester` (string): 学期- **示例请求**: ```bash curl -X POST http://yourdomain.com/api/classes -d '{ "class_name": "History 101", "description": "Basic History Class", "semester": "Fall 2023" }' ```- **响应**: ```json { "message": "Class was created." } ```
### 步程管理
#### 获取所有步程
- **URL**: `/courses`- **方法**: `GET`- **说明**: 获取系统中所有步程的列表。- **请求参数**: 无- **示例请求**: ```bash curl -X GET http://yourdomain.com/api/courses ```- **响应**: ```json [ { "course_id": 1, "course_name": "Algebra", "description": "Algebra Course", "syllabus": "Algebra Syllabus" }, { "course_id": 2, "course_name": "Mechanics", "description": "Mechanics Course", "syllabus": "Mechanics Syllabus" }, ... ] ```
#### 创建步程
- **URL**: `/courses`- **方法**: `POST`- **说明**: 创建一个新的步程。- **请求参数**: - `course_name` (string): 步程名称 - `description` (string): 描述 - `syllabus` (string): 步程大纲- **示例请求**: ```bash curl -X POST http://yourdomain.com/api/courses -d '{ "course_name": "Genetics", "description": "Genetics Course", "syllabus": "Genetics Syllabus" }' ```- **响应**: ```json { "message": "Course was created." } ```
### 视频管理
#### 获取所有视频
- **URL**: `/videos`- **方法**: `GET`- **说明**: 获取系统中所有视频的列表。- **请求参数**: 无- **示例请求**: ```bash curl -X GET http://yourdomain.com/api/videos ```- **响应**: ```json [ { "video_id": 1, "course_id": 1, "title": "Algebra Basics", "description": "Introduction to Algebra", "url": "video1.mp4" }, { "video_id": 2, "course_id": 2, "title": "Newton's Laws", "description": "Introduction to Mechanics", "url": "video2.mp4" }, ... ] ```
#### 上传视频
- **URL**: `/videos`- **方法**: `POST`- **说明**: 上传一个新的视频。- **请求参数**: - `course_id` (int): 步程ID - `title` (string): 视频标题 - `description` (string): 描述 - `url` (string): 视频URL- **示例请求**: ```bash curl -X POST http://yourdomain.com/api/videos -d '{ "course_id": 1, "title": "Algebra Basics", "description": "Introduction to Algebra", "url": "video1.mp4" }' ```- **响应**: ```json { "message": "Video was uploaded." } ```
### 测试题管理
#### 获取所有测试题
- **URL**: `/tests`- **方法**: `GET`- **说明**: 获取系统中所有测试题的列表。- **请求参数**: 无- **示例请求**: ```bash curl -X GET http://yourdomain.com/api/tests ```- **响应**: ```json [ { "test_id": 1, "course_id": 1, "question": "What is 2+2?", "answer": "4", "type": "multiple_choice" }, { "test_id": 2, "course_id": 2, "question": "State Newton's first law of motion.", "answer": "An object in motion stays in motion...", "type": "short_answer" }, ... ] ```
#### 创建测试题
- **URL**: `/tests`- **方法**: `POST`- **说明**: 创建一个新的测试题。- **请求参数**: - `course_id` (int): 步程ID - `question` (string): 问题 - `answer` (string): 答案 - `type` (string): 题目类型(multiple_choice/short_answer/fill_in_the_blank)- **示例请求**: ```bash curl -X POST http://yourdomain.com/api/tests -d '{ "course_id": 1, "question": "What is 2+2?", "answer": "4", "type": "multiple_choice" }' ```- **响应**: ```json { "message": "Test was created." } ```
### 用户评论
#### 获取所有评论
- **URL**: `/comments`- **方法**: `GET`- **说明**: 获取系统中所有评论的列表。- **请求参数**: 无- **示例请求**: ```bash curl -X GET http://yourdomain.com/api/comments ```- **响应**```json [ { "comment_id": 1, "course_id": 1, "user_id": 4, "content": "Great introduction to Algebra!", "created_at": "2024-08-01 12:34:56" }, { "comment_id": 2, "course_id": 2, "user_id": 5, "content": "Found this lecture on Newton's laws very helpful.", "created_at": "2024-08-01 12:35:56" }, ... ] ```
#### 创建评论
- **URL**: `/comments`- **方法**: `POST`- **说明**: 添加一个新的评论。- **请求参数**: - `course_id` (int): 步程ID - `user_id` (int): 用户ID - `content` (string): 评论内容- **示例请求**: ```bash curl -X POST http://yourdomain.com/api/comments -d '{ "course_id": 1, "user_id": 4, "content": "Great introduction to Algebra!" }' ```- **响应**: ```json { "message": "Comment was added." } ```
---
### 错误响应
所有API在发生错误时,都会返回适当的HTTP状态码以及包含错误信息的JSON响应。
- **HTTP 状态码** - `400 Bad Request`:请求无效,通常是因为缺少必需的参数或参数格式错误。 - `401 Unauthorized`:未授权,通常是因为缺少有效的认证信息。 - `404 Not Found`:请求的资源不存在。 - `500 Internal Server Error`:服务器内部错误。
- **示例错误响应** ```json { "message": "Unable to create user." } ```
### 示例调用
以下是使用 `curl` 调用各个API的示例:
#### 获取所有用户
```bashcurl -X GET http://yourdomain.com/api/users```
#### 创建新用户
```bashcurl -X POST http://yourdomain.com/api/users -d '{ "username": "newuser", "password": "password123", "email": "newuser@example.com", "role": "student", "avatar": "avatar.png"}'```
#### 获取所有班级
```bashcurl -X GET http://yourdomain.com/api/classes```
#### 创建新班级
```bashcurl -X POST http://yourdomain.com/api/classes -d '{ "class_name": "History 101", "description": "Basic History Class", "semester": "Fall 2023"}'```
#### 获取所有步程
```bashcurl -X GET http://yourdomain.com/api/courses```
#### 创建新步程
```bashcurl -X POST http://yourdomain.com/api/courses -d '{ "course_name": "Genetics", "description": "Genetics Course", "syllabus": "Genetics Syllabus"}'```
#### 获取所有视频
```bashcurl -X GET http://yourdomain.com/api/videos```
#### 上传新视频
```bashcurl -X POST http://yourdomain.com/api/videos -d '{ "course_id": 1, "title": "Algebra Basics", "description": "Introduction to Algebra", "url": "video1.mp4"}'```
#### 获取所有测试题
```bashcurl -X GET http://yourdomain.com/api/tests```
#### 创建新测试题
```bashcurl -X POST http://yourdomain.com/api/tests -d '{ "course_id": 1, "question": "What is 2+2?", "answer": "4", "type": "multiple_choice"}'```
#### 获取所有评论
```bashcurl -X GET http://yourdomain.com/api/comments```
#### 添加新评论
```bashcurl -X POST http://yourdomain.com/api/comments -d '{ "course_id": 1, "user_id": 4, "content": "Great introduction to Algebra!"}'```
---
### 备注
1. 所有请求都应使用 `Content-Type: application/json` 头信息。2. 数据库连接信息需根据实际部署情况进行配置。3. 为了确保系统安全,请在实际应用中加入认证和授权机制,如JWT(JSON Web Token)。4. 在生产环境中,请确保对所有输入进行严格的验证和消毒,以防止SQL注入和其他安全漏洞。
以上是教学管理系统API的详细说明文档,希望能够帮助你在开发和使用过程中顺利实现各项功能。