cslms-api/internal/routers/quiz.go
2024-01-15 23:08:05 +09:00

52 lines
1.3 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 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)
}