Files
VLoop/internal/http/router.go

34 lines
992 B
Go
Raw Normal View History

package http
import (
"feedsystem_video_go/internal/account"
2025-12-05 14:03:57 +08:00
"feedsystem_video_go/internal/middleware"
"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-05 14:25:39 +08:00
accountGroup.POST("/register", accountHandler.CreateAccount)
accountGroup.POST("/login", accountHandler.Login)
2025-12-05 14:25:39 +08:00
accountGroup.POST("/changePassword", accountHandler.ChangePassword)
accountGroup.POST("/findByID", accountHandler.FindByID)
accountGroup.POST("/findByUsername", accountHandler.FindByUsername)
}
protectedAccountGroup := accountGroup.Group("")
protectedAccountGroup.Use(middleware.JWTAuth())
2025-12-05 14:03:57 +08:00
{
protectedAccountGroup.POST("/logout", accountHandler.Logout)
protectedAccountGroup.POST("/rename", accountHandler.RenameByID)
2025-12-05 14:03:57 +08:00
}
return r
}