AnCao/internal/models/question.go
yanlongqi f791c235e1 添加题目练习功能模块
实现了完整的题目练习功能,包括后端API和前端界面:
- 后端新增题目管理handlers和数据模型
- 前端新增题目展示页面和API调用模块
- 添加题库数据文件支持
- 更新路由配置以集成新功能

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 20:26:53 +08:00

49 lines
1.5 KiB
Go

package models
// QuestionType 题目类型
type QuestionType string
const (
SingleChoice QuestionType = "single" // 单选
MultipleChoice QuestionType = "multiple" // 多选
FillBlank QuestionType = "fill" // 填空
TrueFalse QuestionType = "judge" // 判断
)
// Question 题目模型
type Question struct {
ID int `json:"id"`
Type QuestionType `json:"type"`
Content string `json:"content"` // 题目内容
Options []Option `json:"options"` // 选项(单选、多选、判断使用)
Answer interface{} `json:"-"` // 正确答案(不返回给前端)
Category string `json:"category"` // 分类
}
// Option 选项
type Option struct {
Key string `json:"key"` // 选项标识 A/B/C/D
Value string `json:"value"` // 选项内容
}
// SubmitAnswer 提交答案请求
type SubmitAnswer struct {
QuestionID int `json:"question_id"`
Answer interface{} `json:"answer"` // 可以是字符串、字符串数组等
}
// AnswerResult 答案结果
type AnswerResult struct {
Correct bool `json:"correct"`
CorrectAnswer interface{} `json:"correct_answer"`
Explanation string `json:"explanation,omitempty"` // 答案解析
}
// Statistics 统计数据
type Statistics struct {
TotalQuestions int `json:"total_questions"`
AnsweredQuestions int `json:"answered_questions"`
CorrectAnswers int `json:"correct_answers"`
Accuracy float64 `json:"accuracy"`
}