package routers import ( "awesomeProject/internal/common" "awesomeProject/internal/handlers" "awesomeProject/internal/middleware" "awesomeProject/internal/models" "github.com/gin-gonic/gin" ) // SetupPublicRoutes 设置公共路由 func SetupPublicRoutes(router *gin.Engine) { // 创建handler实例 authHandler := &handlers.AuthHandler{} uploadHandler := handlers.NewUploadHandler() // 公共路由组 publicGroup := router.Group("/back") publicGroup.POST("/upload", uploadHandler.UploadFile) publicGroup.GET("/config", func(context *gin.Context) { db := common.GetDB() key := context.DefaultQuery("key", "") if key == "" { context.JSON(200, common.Error(500, "键值对为空")) return } var config models.SystemConfig db.Where("config_key=?", key).First(&config) context.JSON(200, common.Success(config.ConfigValue)) }) // 认证相关路由(无需token验证) authGroup := publicGroup.Group("/auth") { authGroup.POST("/login", authHandler.Login) // 用户登录 authGroup.POST("/register", authHandler.Register) // 用户注册 authGroup.POST("/send-sms", authHandler.SendSMS) // 发送短信验证码 } // 需要token验证的公共路由 protectedGroup := publicGroup.Group("") protectedGroup.Use(middleware.JWTMiddleware) { protectedGroup.GET("/current-user", authHandler.GetCurrentUser) // 获取当前用户信息 protectedGroup.PUT("/update-profile", authHandler.UpdateProfile) // 更新个人信息 protectedGroup.PUT("/change-password", authHandler.ChangePassword) // 修改密码 // 文件上传路由 // 单文件上传 protectedGroup.POST("/upload/batch", uploadHandler.BatchUploadFiles) // 批量文件上传 } }