Files
lv8girl/internal/routes/routes.go
nannanwu 690b4d5961 fix(admin): 添加管理操作错误处理及更新模板样式
- 管理后台帖子与用户审核操作中添加失败错误重定向处理
- 管理后台帖子、用户、评论删除操作中添加错误检查及提示
- 用户角色更新操作失败时添加错误重定向
- 用户封禁通知失败时添加相应错误提示
- 登录登出时session保存加入错误处理
- 讨论区上传目录创建失败时显示错误提示
- 移除admin_dashboard.html多余样式及修正侧边栏当前页高亮
- admin_posts.html和admin_users.html添加状态样式动态使用的隐藏span元素
- admin_users.html为角色选择添加label以提升无障碍性
- 升级项目依赖版本,包含gin、gorm、validator等核心库版本更新
2026-02-24 21:14:55 +08:00

74 lines
2.5 KiB
Go

package routes
import (
"lv8girl/internal/config"
"lv8girl/internal/controllers"
"lv8girl/internal/middleware"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
)
func SetupRouter() *gin.Engine {
r := gin.Default()
cfg := config.GetConfig()
store := cookie.NewStore([]byte(cfg.Session.Secret))
r.Use(sessions.Sessions(cfg.Session.Name, store))
r.Static("/static", "./static")
r.Static("/uploads", "./uploads")
r.LoadHTMLGlob("templates/*")
authCtrl := controllers.NewAuthController()
homeCtrl := controllers.NewHomeController()
discussionCtrl := controllers.NewDiscussionController()
userCtrl := controllers.NewUserController()
messageCtrl := controllers.NewMessageController()
adminCtrl := controllers.NewAdminController()
r.GET("/", homeCtrl.Index)
r.GET("/login", authCtrl.ShowLogin)
r.POST("/login", authCtrl.Login)
r.GET("/register", authCtrl.ShowRegister)
r.POST("/register", authCtrl.Register)
r.GET("/logout", authCtrl.Logout)
r.GET("/post/:id", homeCtrl.ShowPost)
r.POST("/post/:id/like", middleware.AuthRequired(), homeCtrl.LikePost)
r.POST("/post/:id/comment", middleware.AuthRequired(), homeCtrl.AddComment)
r.GET("/new-post", middleware.AuthRequired(), discussionCtrl.ShowNewPost)
r.POST("/new-post", middleware.AuthRequired(), discussionCtrl.CreatePost)
r.GET("/profile", middleware.AuthRequired(), userCtrl.ShowProfile)
r.GET("/profile/:id", userCtrl.ShowProfile)
r.POST("/upload-avatar", middleware.AuthRequired(), userCtrl.UploadAvatar)
r.GET("/messages", middleware.AuthRequired(), messageCtrl.ShowMessages)
r.GET("/send-message", middleware.AuthRequired(), messageCtrl.ShowSendMessage)
r.POST("/send-message", middleware.AuthRequired(), messageCtrl.SendMessage)
admin := r.Group("/admin")
admin.Use(middleware.AdminRequired())
{
admin.GET("", adminCtrl.Dashboard)
admin.GET("/", adminCtrl.Dashboard)
admin.GET("/pending_posts", adminCtrl.PendingPosts)
admin.GET("/pending_posts/:action/:id", adminCtrl.ApprovePost)
admin.GET("/pending_users", adminCtrl.PendingUsers)
admin.GET("/pending_users/:action/:id", adminCtrl.ApproveUser)
admin.GET("/posts", adminCtrl.Posts)
admin.GET("/posts/delete/:id", adminCtrl.DeletePost)
admin.GET("/users", adminCtrl.Users)
admin.POST("/users/role", adminCtrl.UpdateUserRole)
admin.GET("/users/delete/:id", adminCtrl.DeleteUser)
admin.GET("/comments", adminCtrl.Comments)
admin.GET("/comments/delete/:id", adminCtrl.DeleteComment)
}
return r
}