54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
|
package routers
|
||
|
|
||
|
import (
|
||
|
"learnsteam/cslms-api/internal/controllers"
|
||
|
"learnsteam/cslms-api/internal/middleware"
|
||
|
"learnsteam/cslms-api/internal/repositories"
|
||
|
"learnsteam/cslms-api/internal/services"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
func InitCenterRouter(db *gorm.DB, router *gin.Engine) {
|
||
|
r := NewCenterRouter(db, router)
|
||
|
r.SetCenterRouter()
|
||
|
}
|
||
|
|
||
|
type CenterRouter interface {
|
||
|
SetRouter(db *gorm.DB, router *gin.Engine)
|
||
|
}
|
||
|
|
||
|
type centerRouter struct {
|
||
|
db *gorm.DB
|
||
|
repository repositories.CenterRepository
|
||
|
service services.CenterService
|
||
|
controller controllers.CenterController
|
||
|
router *gin.Engine
|
||
|
}
|
||
|
|
||
|
func NewCenterRouter(db *gorm.DB, router *gin.Engine) *centerRouter {
|
||
|
repository := repositories.NewCenterRepository(db)
|
||
|
tokenRepository := repositories.NewTokenRepository(db)
|
||
|
service := services.NewCenterService(repository, tokenRepository)
|
||
|
|
||
|
tokenService := services.NewTokenService(tokenRepository)
|
||
|
controller := controllers.NewCenterController(service, tokenService)
|
||
|
|
||
|
return ¢erRouter{
|
||
|
db: db,
|
||
|
repository: repository,
|
||
|
service: service,
|
||
|
controller: controller,
|
||
|
router: router,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *centerRouter) SetCenterRouter() {
|
||
|
group := r.router.Group("/center")
|
||
|
group.GET("", middleware.Auth("admin"), r.controller.List)
|
||
|
group.GET("/:id", middleware.Auth("admin"), r.controller.Find)
|
||
|
group.POST("", middleware.Auth("admin"), r.controller.Create)
|
||
|
group.PUT("/:id", middleware.Auth("admin"), r.controller.Update)
|
||
|
}
|