This commit is contained in:
2026-02-23 23:50:04 +08:00
commit 084d3b0faf
45 changed files with 4090 additions and 0 deletions

72
internal/routes/routes.go Normal file
View File

@@ -0,0 +1,72 @@
package routes
import (
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"lv8girl/internal/config"
"lv8girl/internal/controllers"
"lv8girl/internal/middleware"
)
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
}