2025-12-05 09:59:57 +08:00
|
|
|
package http
|
2025-12-04 17:09:04 +08:00
|
|
|
|
|
|
|
|
import (
|
2025-12-05 09:59:57 +08:00
|
|
|
"feedsystem_video_go/internal/account"
|
2025-12-05 14:03:57 +08:00
|
|
|
"feedsystem_video_go/internal/middleware"
|
2025-12-04 17:09:04 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func SetRouter(db *gorm.DB) *gin.Engine {
|
|
|
|
|
r := gin.Default()
|
|
|
|
|
|
2025-12-05 14:25:39 +08:00
|
|
|
accountRepository := account.NewAccountRepository(db)
|
|
|
|
|
accountService := account.NewAccountService(accountRepository)
|
|
|
|
|
accountHandler := NewAccountHandler(accountService)
|
|
|
|
|
accountGroup := r.Group("/account")
|
2025-12-04 17:09:04 +08:00
|
|
|
{
|
2025-12-05 14:25:39 +08:00
|
|
|
accountGroup.POST("/register", accountHandler.CreateAccount)
|
|
|
|
|
accountGroup.POST("/rename", accountHandler.RenameByID)
|
|
|
|
|
accountGroup.POST("/changePassword", accountHandler.ChangePassword)
|
|
|
|
|
accountGroup.POST("/findByID", accountHandler.FindByID)
|
|
|
|
|
accountGroup.POST("/findByUsername", accountHandler.FindByUsername)
|
2025-12-04 17:09:04 +08:00
|
|
|
}
|
2025-12-05 14:03:57 +08:00
|
|
|
authGroup := r.Group("/auth")
|
|
|
|
|
{
|
2025-12-05 14:25:39 +08:00
|
|
|
authGroup.POST("/login", accountHandler.Login)
|
2025-12-05 14:03:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protectedAuthGroup := authGroup.Group("")
|
|
|
|
|
protectedAuthGroup.Use(middleware.JWTAuth())
|
|
|
|
|
{
|
2025-12-05 14:25:39 +08:00
|
|
|
protectedAuthGroup.POST("/logout", accountHandler.Logout)
|
2025-12-05 14:03:57 +08:00
|
|
|
}
|
2025-12-04 17:09:04 +08:00
|
|
|
|
|
|
|
|
return r
|
|
|
|
|
}
|