修复每日一练继续答题功能
问题:点击首页的每日一练快捷入口时,无法检测到未完成的考试记录 原因:GetExamRecordList 接口在指定 exam_id 参数时,仅返回 status='graded' 的记录, 过滤掉了 status='in_progress' 的未完成记录 修改: - 移除 status='graded' 过滤条件 - 添加 user_id 过滤,确保用户只能查看自己的记录 - 修改排序为按创建时间倒序(最新的在前) - 支持继续未完成的考试答题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d04de0190c
commit
f9a5e06df2
@ -672,14 +672,15 @@ func GetExamRecordList(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询该试卷的所有已完成考试记录(包含用户信息)
|
// 查询该试卷的所有考试记录(包含用户信息)
|
||||||
|
// 注意:包含 in_progress 状态的记录,以支持继续答题功能
|
||||||
var records []models.ExamRecord
|
var records []models.ExamRecord
|
||||||
if err := db.Where("exam_id = ? AND status = ?", examID, "graded").
|
if err := db.Where("exam_id = ? AND user_id = ?", examID, userID).
|
||||||
Preload("Exam").
|
Preload("Exam").
|
||||||
Preload("User", func(db *gorm.DB) *gorm.DB {
|
Preload("User", func(db *gorm.DB) *gorm.DB {
|
||||||
return db.Select("id", "username", "nickname", "avatar")
|
return db.Select("id", "username", "nickname", "avatar")
|
||||||
}).
|
}).
|
||||||
Order("score DESC, created_at DESC").
|
Order("created_at DESC").
|
||||||
Find(&records).Error; err != nil {
|
Find(&records).Error; err != nil {
|
||||||
log.Printf("查询考试记录失败: %v", err)
|
log.Printf("查询考试记录失败: %v", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": "查询考试记录失败"})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": "查询考试记录失败"})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user