2023-12-27 17:31:49 +09:00
|
|
|
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)
|
2024-01-15 23:08:05 +09:00
|
|
|
group.DELETE("/:id", middleware.Auth("admin"), r.controller.Delete)
|
2023-12-27 17:31:49 +09:00
|
|
|
}
|