package routers import ( "learnsteam/learsteam-quiz-api/internal/controllers" "learnsteam/learsteam-quiz-api/internal/middleware" "learnsteam/learsteam-quiz-api/internal/repositories" "learnsteam/learsteam-quiz-api/internal/services" "github.com/gin-gonic/gin" "gorm.io/gorm" ) func InitProgramRouter(db *gorm.DB, router *gin.Engine) { r := NewProgramRouter(db, router) r.SetProgramRouter(db, router) } type ProgramRouter interface { SetRouter(db *gorm.DB, router *gin.Engine) } type programRouter struct { db *gorm.DB repository repositories.ProgramRepository service services.ProgramService controller controllers.ProgramController router *gin.Engine } func NewProgramRouter(db *gorm.DB, router *gin.Engine) *programRouter { repository := repositories.NewProgramRepository(db) service := services.NewProgramService(repository) controller := controllers.NewProgramController(service) return &programRouter{ db: db, repository: repository, service: service, controller: controller, router: router, } } func (r *programRouter) SetProgramRouter(db *gorm.DB, router *gin.Engine) { group := router.Group("/program") group.GET("", middleware.Auth(), r.controller.List) group.GET("/:id", middleware.Auth(), r.controller.Find) group.POST("", middleware.Auth(), r.controller.Create) group.PUT("/:id", middleware.Auth(), r.controller.Update) }