feat: 完成后端-管理后台集成及部署配置
🚀 主要功能: - 完善后端API服务层,实现完整的CRUD操作 - 开发管理后台所有核心页面 (仪表板、照片、分类、标签、用户、设置) - 完成前后端完全集成,所有API接口正常对接 - 配置完整的CI/CD流水线,支持自动化部署 🎯 后端完善: - 实现PhotoService, CategoryService, TagService, UserService - 添加完整的API处理器和路由配置 - 支持Docker容器化部署 - 添加数据库迁移和健康检查 🎨 管理后台完成: - 仪表板: 实时统计数据展示 - 照片管理: 完整的CRUD操作,支持批量处理 - 分类管理: 树形结构展示和管理 - 标签管理: 颜色标签和统计信息 - 用户管理: 角色权限控制 - 系统设置: 多标签配置界面 - 添加pre-commit代码质量检查 🔧 部署配置: - Docker Compose完整配置 - 后端CI/CD流水线 (Docker部署) - 管理后台CI/CD流水线 (静态文件部署) - 前端CI/CD流水线优化 - 自动化脚本: 部署、备份、监控 - 完整的部署文档和运维指南 ✅ 集成完成: - 所有API接口正常连接 - 认证系统完整集成 - 数据获取和状态管理 - 错误处理和用户反馈 - 响应式设计优化
This commit is contained in:
@ -1,44 +1,131 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"photography-backend/internal/api/handlers"
|
||||
"photography-backend/internal/api/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Handlers 处理器集合
|
||||
type Handlers struct {
|
||||
Auth *handlers.AuthHandler
|
||||
AuthHandler *handlers.AuthHandler
|
||||
UserHandler *handlers.UserHandler
|
||||
PhotoHandler *handlers.PhotoHandler
|
||||
CategoryHandler *handlers.CategoryHandler
|
||||
TagHandler *handlers.TagHandler
|
||||
}
|
||||
|
||||
// SetupRoutes 设置路由
|
||||
func SetupRoutes(r *gin.Engine, handlers *Handlers, authMiddleware *middleware.AuthMiddleware) {
|
||||
// API v1路由组
|
||||
v1 := r.Group("/api/v1")
|
||||
|
||||
// 公开路由
|
||||
public := v1.Group("/auth")
|
||||
func SetupRoutes(r *gin.Engine, h *Handlers, authMiddleware *middleware.AuthMiddleware, logger *zap.Logger) {
|
||||
// 健康检查
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"status": "ok"})
|
||||
})
|
||||
|
||||
// API 路由组
|
||||
api := r.Group("/api")
|
||||
{
|
||||
public.POST("/login", handlers.Auth.Login)
|
||||
public.POST("/register", handlers.Auth.Register)
|
||||
public.POST("/refresh", handlers.Auth.RefreshToken)
|
||||
// 公开路由
|
||||
public := api.Group("")
|
||||
{
|
||||
// 认证相关
|
||||
auth := public.Group("/auth")
|
||||
{
|
||||
auth.POST("/login", h.AuthHandler.Login)
|
||||
auth.POST("/refresh", h.AuthHandler.RefreshToken)
|
||||
}
|
||||
}
|
||||
|
||||
// 需要认证的路由
|
||||
protected := api.Group("")
|
||||
protected.Use(authMiddleware.RequireAuth())
|
||||
{
|
||||
// 当前用户信息
|
||||
protected.GET("/me", h.UserHandler.GetCurrentUser)
|
||||
protected.PUT("/me", h.UserHandler.UpdateCurrentUser)
|
||||
protected.POST("/auth/logout", h.AuthHandler.Logout)
|
||||
|
||||
// 照片管理
|
||||
photos := protected.Group("/photos")
|
||||
{
|
||||
photos.GET("", h.PhotoHandler.GetPhotos)
|
||||
photos.POST("", h.PhotoHandler.CreatePhoto)
|
||||
photos.GET("/stats", h.PhotoHandler.GetPhotoStats)
|
||||
photos.POST("/upload", h.PhotoHandler.UploadPhoto)
|
||||
photos.POST("/batch/update", h.PhotoHandler.BatchUpdatePhotos)
|
||||
photos.POST("/batch/delete", h.PhotoHandler.BatchDeletePhotos)
|
||||
photos.GET("/:id", h.PhotoHandler.GetPhoto)
|
||||
photos.PUT("/:id", h.PhotoHandler.UpdatePhoto)
|
||||
photos.DELETE("/:id", h.PhotoHandler.DeletePhoto)
|
||||
}
|
||||
|
||||
// 分类管理
|
||||
categories := protected.Group("/categories")
|
||||
{
|
||||
categories.GET("", h.CategoryHandler.GetCategories)
|
||||
categories.POST("", h.CategoryHandler.CreateCategory)
|
||||
categories.GET("/tree", h.CategoryHandler.GetCategoryTree)
|
||||
categories.GET("/stats", h.CategoryHandler.GetCategoryStats)
|
||||
categories.POST("/reorder", h.CategoryHandler.ReorderCategories)
|
||||
categories.POST("/generate-slug", h.CategoryHandler.GenerateSlug)
|
||||
categories.GET("/:id", h.CategoryHandler.GetCategory)
|
||||
categories.PUT("/:id", h.CategoryHandler.UpdateCategory)
|
||||
categories.DELETE("/:id", h.CategoryHandler.DeleteCategory)
|
||||
categories.GET("/slug/:slug", h.CategoryHandler.GetCategoryBySlug)
|
||||
}
|
||||
|
||||
// 标签管理
|
||||
tags := protected.Group("/tags")
|
||||
{
|
||||
tags.GET("", h.TagHandler.GetTags)
|
||||
tags.POST("", h.TagHandler.CreateTag)
|
||||
tags.GET("/all", h.TagHandler.GetAllTags)
|
||||
tags.GET("/popular", h.TagHandler.GetPopularTags)
|
||||
tags.GET("/cloud", h.TagHandler.GetTagCloud)
|
||||
tags.GET("/stats", h.TagHandler.GetTagStats)
|
||||
tags.GET("/search", h.TagHandler.SearchTags)
|
||||
tags.POST("/batch/delete", h.TagHandler.BatchDeleteTags)
|
||||
tags.POST("/generate-slug", h.TagHandler.GenerateSlug)
|
||||
tags.GET("/:id", h.TagHandler.GetTag)
|
||||
tags.PUT("/:id", h.TagHandler.UpdateTag)
|
||||
tags.DELETE("/:id", h.TagHandler.DeleteTag)
|
||||
tags.GET("/slug/:slug", h.TagHandler.GetTagBySlug)
|
||||
}
|
||||
|
||||
// 用户管理 (需要管理员权限)
|
||||
admin := protected.Group("/admin")
|
||||
admin.Use(authMiddleware.RequireRole("admin"))
|
||||
{
|
||||
users := admin.Group("/users")
|
||||
{
|
||||
users.GET("", h.UserHandler.GetUsers)
|
||||
users.POST("", h.UserHandler.CreateUser)
|
||||
users.GET("/:id", h.UserHandler.GetUser)
|
||||
users.PUT("/:id", h.UserHandler.UpdateUser)
|
||||
users.DELETE("/:id", h.UserHandler.DeleteUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 需要认证的路由
|
||||
protected := v1.Group("/")
|
||||
protected.Use(authMiddleware.RequireAuth())
|
||||
|
||||
// 前端公共 API (无需认证)
|
||||
frontend := api.Group("/public")
|
||||
{
|
||||
// 用户资料
|
||||
protected.GET("/auth/profile", handlers.Auth.GetProfile)
|
||||
protected.PUT("/auth/password", handlers.Auth.UpdatePassword)
|
||||
protected.POST("/auth/logout", handlers.Auth.Logout)
|
||||
}
|
||||
|
||||
// 管理员路由
|
||||
admin := v1.Group("/admin")
|
||||
admin.Use(authMiddleware.RequireAuth())
|
||||
admin.Use(authMiddleware.RequireAdmin())
|
||||
{
|
||||
// 将在后续添加管理员相关路由
|
||||
// 公开的照片接口
|
||||
frontend.GET("/photos", h.PhotoHandler.GetPhotos)
|
||||
frontend.GET("/photos/:id", h.PhotoHandler.GetPhoto)
|
||||
|
||||
// 公开的分类接口
|
||||
frontend.GET("/categories", h.CategoryHandler.GetCategories)
|
||||
frontend.GET("/categories/tree", h.CategoryHandler.GetCategoryTree)
|
||||
frontend.GET("/categories/:id", h.CategoryHandler.GetCategory)
|
||||
frontend.GET("/categories/slug/:slug", h.CategoryHandler.GetCategoryBySlug)
|
||||
|
||||
// 公开的标签接口
|
||||
frontend.GET("/tags", h.TagHandler.GetTags)
|
||||
frontend.GET("/tags/popular", h.TagHandler.GetPopularTags)
|
||||
frontend.GET("/tags/cloud", h.TagHandler.GetTagCloud)
|
||||
frontend.GET("/tags/:id", h.TagHandler.GetTag)
|
||||
frontend.GET("/tags/slug/:slug", h.TagHandler.GetTagBySlug)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user