AnCao/internal/models/practice_question.go
yanlongqi a7ede7692f 实现完整的题目练习功能模块
- 后端功能:
  * 新增练习题数据模型和数据库表结构
  * 实现题目列表、随机题目、提交答案等API接口
  * 支持5种题型:单选、多选、判断、填空、简答
  * 判断题自动生成"对/错"选项
  * 前后端类型映射(single/multiple/judge/fill/short)

- 前端功能:
  * 新增首页,展示5种题型选择卡片和统计信息
  * 完善答题页面,支持所有题型的渲染和答题
  * 填空题特殊渲染:将****替换为横线输入框
  * 实现题目列表、筛选、随机练习等功能
  * 优化底部导航,添加首页、答题、我的三个标签

- 工具脚本:
  * 新增题目数据导入脚本
  * 支持从JSON文件批量导入题库

- 文档更新:
  * 更新CLAUDE.md和README.md,记录新增功能

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 02:39:18 +08:00

53 lines
2.3 KiB
Go

package models
import "gorm.io/gorm"
// PracticeQuestionType 题目类型
type PracticeQuestionType string
const (
FillInBlank PracticeQuestionType = "fill-in-blank" // 填空题
TrueFalseType PracticeQuestionType = "true-false" // 判断题
MultipleChoiceQ PracticeQuestionType = "multiple-choice" // 单选题
MultipleSelection PracticeQuestionType = "multiple-selection" // 多选题
ShortAnswer PracticeQuestionType = "short-answer" // 简答题
)
// PracticeQuestion 练习题目模型
type PracticeQuestion struct {
gorm.Model
QuestionID string `gorm:"size:50;not null" json:"question_id"` // 题目ID (原JSON中的id字段)
Type PracticeQuestionType `gorm:"index;size:30;not null" json:"type"` // 题目类型
TypeName string `gorm:"size:50" json:"type_name"` // 题型名称(中文)
Question string `gorm:"type:text;not null" json:"question"` // 题目内容
AnswerData string `gorm:"type:text;not null" json:"-"` // 答案数据(JSON格式存储)
OptionsData string `gorm:"type:text" json:"-"` // 选项数据(JSON格式存储,用于选择题)
}
// TableName 指定表名
func (PracticeQuestion) TableName() string {
return "practice_questions"
}
// PracticeQuestionDTO 用于前端返回的数据传输对象
type PracticeQuestionDTO struct {
ID uint `json:"id"`
Type string `json:"type"` // 前端使用的简化类型: single, multiple, judge, fill
Content string `json:"content"` // 题目内容
Options []Option `json:"options"` // 选择题选项数组
Category string `json:"category"` // 题目分类
}
// PracticeAnswerSubmit 练习题答案提交
type PracticeAnswerSubmit struct {
QuestionID uint `json:"question_id" binding:"required"` // 数据库ID
Answer interface{} `json:"answer" binding:"required"` // 用户答案
}
// PracticeAnswerResult 练习题答案结果
type PracticeAnswerResult struct {
Correct bool `json:"correct"` // 是否正确
UserAnswer interface{} `json:"user_answer"` // 用户答案
CorrectAnswer interface{} `json:"correct_answer,omitempty"` // 正确答案(仅在错误时返回)
}