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 InitQuizRouter(db *gorm.DB, router *gin.Engine) { r := NewQuizRouter(db, router) r.SetQuizRouter() } type QuizRouter interface { SetRouter(db *gorm.DB, router *gin.Engine) } type quizRouter struct { db *gorm.DB repository repositories.QuizRepository service services.QuizService controller controllers.QuizController router *gin.Engine } func NewQuizRouter(db *gorm.DB, router *gin.Engine) *quizRouter { repository := repositories.NewQuizRepository(db) service := services.NewQuizService(repository) controller := controllers.NewQuizController(service) return &quizRouter{ db: db, repository: repository, service: service, controller: controller, router: router, } } func (r *quizRouter) SetQuizRouter() { group := r.router.Group("/quiz") 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) group.DELETE("/:id", middleware.Auth("admin"), r.controller.Delete) }