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 InitQuizPaperRouter(db *gorm.DB, router *gin.Engine) { r := NewQuizPaperRouter(db, router) r.SetQuizPaperRouter() } type QuizPaperRouter interface { SetRouter(db *gorm.DB, router *gin.Engine) } type quizPaperRouter struct { db *gorm.DB repository repositories.QuizPaperRepository quizRepository repositories.QuizRepository service services.QuizPaperService quizService services.QuizService controller controllers.QuizPaperController router *gin.Engine } func NewQuizPaperRouter(db *gorm.DB, router *gin.Engine) *quizPaperRouter { repository := repositories.NewQuizPaperRepository(db) quizRepository := repositories.NewQuizRepository(db) service := services.NewQuizPaperService(repository) quizService := services.NewQuizService(quizRepository) controller := controllers.NewQuizPaperController(service, quizService) return &quizPaperRouter{ db: db, repository: repository, quizRepository: quizRepository, service: service, quizService: quizService, controller: controller, router: router, } } func (r *quizPaperRouter) SetQuizPaperRouter() { group := r.router.Group("/quizpaper") 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.POST("/:id/copy", middleware.Auth("admin"), r.controller.Copy) }