**新增功能**: - 新增删除单个错题的接口 (DELETE /api/wrong-questions/:id) - 错题列表每个项添加删除按钮 - 支持单独删除不想要的错题记录 **技术实现**: - 后端: 实现DeleteWrongQuestion处理器,确保用户只能删除自己的错题 - 前端: 添加deleteWrongQuestion API 调用 - UI: 在List.Item中添加actions属性,显示删除按钮 - 删除时显示二次确认弹窗 **注意事项**: - 删除需要确认,防止误操作 - 删除成功后自动刷新列表 - 仅显示操作用户自己的错题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
2.2 KiB
Go
69 lines
2.2 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.GET("/practice/types", handlers.GetPracticeQuestionTypes) // 获取题型列表
|
|
|
|
// 需要认证的路由
|
|
auth := api.Group("", middleware.Auth())
|
|
{
|
|
// 练习题提交(需要登录才能记录错题)
|
|
auth.POST("/practice/submit", handlers.SubmitPracticeAnswer) // 提交练习答案
|
|
auth.GET("/practice/statistics", handlers.GetStatistics) // 获取统计数据
|
|
|
|
// 错题本相关API
|
|
auth.GET("/wrong-questions", handlers.GetWrongQuestions) // 获取错题列表
|
|
auth.GET("/wrong-questions/stats", handlers.GetWrongQuestionStats) // 获取错题统计
|
|
auth.GET("/wrong-questions/random", handlers.GetRandomWrongQuestion) // 获取随机错题
|
|
auth.DELETE("/wrong-questions/:id", handlers.DeleteWrongQuestion) // 删除单个错题
|
|
auth.PUT("/wrong-questions/:id/mastered", handlers.MarkWrongQuestionMastered) // 标记已掌握
|
|
auth.DELETE("/wrong-questions", handlers.ClearWrongQuestions) // 清空错题本
|
|
}
|
|
}
|
|
|
|
// 启动服务器
|
|
port := ":8080"
|
|
if err := r.Run(port); err != nil {
|
|
panic("服务器启动失败: " + err.Error())
|
|
}
|
|
}
|