后端实现: - 创建错题数据模型和数据库表结构 - 实现错题记录、查询、统计、标记和清空API - 答题错误时自动记录到错题本 - 支持重复错误累计次数和更新时间 前端实现: - 创建错题本页面,支持查看、筛选和管理错题 - 实现错题统计展示(总数、已掌握、待掌握) - 支持标记已掌握、清空错题本和重做题目 - 在首页和个人中心添加错题本入口 - 完整的响应式设计适配移动端和PC端 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"ankao/internal/database"
|
|
"ankao/internal/handlers"
|
|
"ankao/internal/middleware"
|
|
"log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func main() {
|
|
// 初始化数据库连接
|
|
if err := database.InitDB(); err != nil {
|
|
log.Fatal("数据库初始化失败:", err)
|
|
}
|
|
log.Println("数据库连接成功")
|
|
|
|
// 创建Gin路由器
|
|
r := gin.Default()
|
|
|
|
// 应用自定义中间件
|
|
r.Use(middleware.CORS())
|
|
r.Use(middleware.Logger())
|
|
|
|
// 静态文件服务
|
|
r.Static("/static", "./web/static")
|
|
r.StaticFile("/", "./web/index.html")
|
|
|
|
// API路由组
|
|
api := r.Group("/api")
|
|
{
|
|
// 健康检查
|
|
api.GET("/health", handlers.HealthCheckHandler)
|
|
|
|
// 用户相关API
|
|
api.POST("/login", handlers.Login) // 用户登录
|
|
api.POST("/register", handlers.Register) // 用户注册
|
|
|
|
// 练习题相关API
|
|
api.GET("/practice/questions", handlers.GetPracticeQuestions) // 获取练习题目列表
|
|
api.GET("/practice/questions/random", handlers.GetRandomPracticeQuestion) // 获取随机练习题目
|
|
api.GET("/practice/questions/:id", handlers.GetPracticeQuestionByID) // 获取指定练习题目
|
|
api.POST("/practice/submit", handlers.SubmitPracticeAnswer) // 提交练习答案
|
|
api.GET("/practice/types", handlers.GetPracticeQuestionTypes) // 获取题型列表
|
|
|
|
// 错题本相关API
|
|
api.GET("/wrong-questions", handlers.GetWrongQuestions) // 获取错题列表
|
|
api.GET("/wrong-questions/stats", handlers.GetWrongQuestionStats) // 获取错题统计
|
|
api.PUT("/wrong-questions/:id/mastered", handlers.MarkWrongQuestionMastered) // 标记已掌握
|
|
api.DELETE("/wrong-questions", handlers.ClearWrongQuestions) // 清空错题本
|
|
}
|
|
|
|
// 启动服务器
|
|
port := ":8080"
|
|
if err := r.Run(port); err != nil {
|
|
panic("服务器启动失败: " + err.Error())
|
|
}
|
|
}
|