主要变更: - 数据库ID字段统一从 uint 改为 int64,提升数据容量和兼容性 - 重构答题检查逻辑,采用策略模式替代 switch-case - 新增 PracticeProgress 模型,支持练习进度持久化 - 优化错题本系统,自动记录答题进度和错误历史 - 添加 lib/pq PostgreSQL 驱动依赖 - 移除错题标签管理 API(待后续迁移) - 前端类型定义同步更新,适配后端模型变更 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package models
|
|
|
|
import (
|
|
"gorm.io/datatypes"
|
|
"time"
|
|
)
|
|
|
|
// UserAnswerRecord 用户答题记录
|
|
type UserAnswerRecord struct {
|
|
ID int64 `gorm:"primarykey"`
|
|
UserID int64 `gorm:"index;not null" json:"user_id"` // 用户ID
|
|
QuestionID int64 `gorm:"index;not null" json:"question_id"` // 题目ID
|
|
IsCorrect bool `gorm:"not null" json:"is_correct"` // 是否答对
|
|
AnsweredAt time.Time `gorm:"not null" json:"answered_at"` // 答题时间
|
|
UserAnswer datatypes.JSON `gorm:"json" json:"user_answer"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (UserAnswerRecord) TableName() string {
|
|
return "user_answer_records"
|
|
}
|
|
|
|
// UserStatistics 用户统计数据
|
|
type UserStatistics struct {
|
|
TotalQuestions int `json:"total_questions"` // 题库总数
|
|
AnsweredQuestions int `json:"answered_questions"` // 已答题数
|
|
CorrectAnswers int `json:"correct_answers"` // 答对题数
|
|
WrongQuestions int `json:"wrong_questions"` // 错题数量
|
|
Accuracy float64 `json:"accuracy"` // 正确率
|
|
}
|