Files
backend/internal/handler/routes.go

143 lines
4.4 KiB
Go
Raw Normal View History

package handler
import (
"carrotskin/internal/middleware"
"carrotskin/internal/model"
"github.com/gin-gonic/gin"
)
// RegisterRoutes 注册所有路由
func RegisterRoutes(router *gin.Engine) {
// 设置Swagger文档
SetupSwagger(router)
// API路由组
v1 := router.Group("/api/v1")
{
// 认证路由无需JWT
authGroup := v1.Group("/auth")
{
authGroup.POST("/register", Register)
authGroup.POST("/login", Login)
authGroup.POST("/send-code", SendVerificationCode)
authGroup.POST("/reset-password", ResetPassword)
}
// 用户路由需要JWT认证
userGroup := v1.Group("/user")
userGroup.Use(middleware.AuthMiddleware())
{
userGroup.GET("/profile", GetUserProfile)
userGroup.PUT("/profile", UpdateUserProfile)
// 头像相关
userGroup.POST("/avatar/upload-url", GenerateAvatarUploadURL)
userGroup.PUT("/avatar", UpdateAvatar)
// 更换邮箱
userGroup.POST("/change-email", ChangeEmail)
// Yggdrasil密码相关
userGroup.POST("/yggdrasil-password/reset", ResetYggdrasilPassword) // 重置Yggdrasil密码并返回新密码
}
// 材质路由
textureGroup := v1.Group("/texture")
{
// 公开路由(无需认证)
textureGroup.GET("", SearchTextures) // 搜索材质
textureGroup.GET("/:id", GetTexture) // 获取材质详情
// 需要认证的路由
textureAuth := textureGroup.Group("")
textureAuth.Use(middleware.AuthMiddleware())
{
textureAuth.POST("/upload-url", GenerateTextureUploadURL) // 生成上传URL
textureAuth.POST("", CreateTexture) // 创建材质记录
textureAuth.PUT("/:id", UpdateTexture) // 更新材质
textureAuth.DELETE("/:id", DeleteTexture) // 删除材质
textureAuth.POST("/:id/favorite", ToggleFavorite) // 切换收藏
textureAuth.GET("/my", GetUserTextures) // 我的材质
textureAuth.GET("/favorites", GetUserFavorites) // 我的收藏
}
}
// 档案路由
profileGroup := v1.Group("/profile")
{
// 公开路由(无需认证)
profileGroup.GET("/:uuid", GetProfile) // 获取档案详情
// 需要认证的路由
profileAuth := profileGroup.Group("")
profileAuth.Use(middleware.AuthMiddleware())
{
profileAuth.POST("/", CreateProfile) // 创建档案
profileAuth.GET("/", GetProfiles) // 获取我的档案列表
profileAuth.PUT("/:uuid", UpdateProfile) // 更新档案
profileAuth.DELETE("/:uuid", DeleteProfile) // 删除档案
profileAuth.POST("/:uuid/activate", SetActiveProfile) // 设置活跃档案
}
}
// 验证码路由
captchaGroup := v1.Group("/captcha")
{
captchaGroup.GET("/generate", Generate) //生成验证码
captchaGroup.POST("/verify", Verify) //验证验证码
}
// Yggdrasil API路由组
ygg := v1.Group("/yggdrasil")
{
ygg.GET("", GetMetaData)
ygg.POST("/minecraftservices/player/certificates", GetPlayerCertificates)
authserver := ygg.Group("/authserver")
{
authserver.POST("/authenticate", Authenticate)
authserver.POST("/validate", ValidToken)
authserver.POST("/refresh", RefreshToken)
authserver.POST("/invalidate", InvalidToken)
authserver.POST("/signout", SignOut)
}
sessionServer := ygg.Group("/sessionserver")
{
sessionServer.GET("/session/minecraft/profile/:uuid", GetProfileByUUID)
sessionServer.POST("/session/minecraft/join", JoinServer)
sessionServer.GET("/session/minecraft/hasJoined", HasJoinedServer)
}
api := ygg.Group("/api")
profiles := api.Group("/profiles")
{
profiles.POST("/minecraft", GetProfilesByName)
}
}
// 系统路由
system := v1.Group("/system")
{
system.GET("/config", GetSystemConfig)
}
}
}
// 以下是系统配置相关的占位符函数,待后续实现
// GetSystemConfig 获取系统配置
// @Summary 获取系统配置
// @Description 获取公开的系统配置信息
// @Tags system
// @Accept json
// @Produce json
// @Success 200 {object} model.Response "获取成功"
// @Router /api/v1/system/config [get]
func GetSystemConfig(c *gin.Context) {
// TODO: 实现从数据库读取系统配置
c.JSON(200, model.NewSuccessResponse(gin.H{
"site_name": "CarrotSkin",
"site_description": "A Minecraft Skin Station",
"registration_enabled": true,
"max_textures_per_user": 100,
"max_profiles_per_user": 5,
}))
}