learnsteam-quiz-api/internal/routers/token.go
2023-11-17 01:38:01 +09:00

47 lines
1.1 KiB
Go

package routers
import (
"learnsteam/learsteam-quiz-api/internal/controllers"
"learnsteam/learsteam-quiz-api/internal/repositories"
"learnsteam/learsteam-quiz-api/internal/services"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func InitTokenRouter(db *gorm.DB, router *gin.Engine) {
r := NewTokenRouter(db, router)
r.SetTokenRouter(db, router)
}
type TokenRouter interface {
SetRouter(db *gorm.DB, router *gin.Engine)
}
type tokenRouter struct {
db *gorm.DB
repository repositories.TokenRepository
service services.TokenService
controller controllers.TokenController
router *gin.Engine
}
func NewTokenRouter(db *gorm.DB, router *gin.Engine) *tokenRouter {
repository := repositories.NewTokenRepository(db)
service := services.NewTokenService(repository)
controller := controllers.NewTokenController(service)
return &tokenRouter{
db: db,
repository: repository,
service: service,
controller: controller,
router: router,
}
}
func (r *tokenRouter) SetTokenRouter(db *gorm.DB, router *gin.Engine) {
group := router.Group("/token")
group.POST("refresh", r.controller.Refresh)
}