cslms-api/internal/routers/userquiz.go
2023-12-27 17:31:49 +09:00

54 lines
1.5 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 InitUserQuizRouter(db *gorm.DB, router *gin.Engine) {
r := NewUserQuizRouter(db, router)
r.SetUserQuizRouter()
}
type UserQuizRouter interface {
SetRouter(db *gorm.DB, router *gin.Engine)
}
type userQuizRouter struct {
db *gorm.DB
repository repositories.UserQuizRepository
quizRepository repositories.QuizRepository
service services.UserQuizService
controller controllers.UserQuizController
router *gin.Engine
}
func NewUserQuizRouter(db *gorm.DB, router *gin.Engine) *userQuizRouter {
repository := repositories.NewUserQuizRepository(db)
quizRepostory := repositories.NewQuizRepository(db)
service := services.NewUserQuizService(repository, quizRepostory)
controller := controllers.NewUserQuizController(service)
return &userQuizRouter{
db: db,
repository: repository,
quizRepository: quizRepostory,
service: service,
controller: controller,
router: router,
}
}
func (r *userQuizRouter) SetUserQuizRouter() {
group := r.router.Group("/userquiz")
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)
}