70 lines
2.6 KiB
Go
70 lines
2.6 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
|
|
userquizRepository repositories.UserQuizRepository
|
|
userquizpaperRepository repositories.UserQuizPaperRepository
|
|
service services.UserQuizService
|
|
quizService services.QuizService
|
|
userquizService services.UserQuizService
|
|
userquizpaperService services.UserQuizPaperService
|
|
controller controllers.UserQuizController
|
|
router *gin.Engine
|
|
}
|
|
|
|
func NewUserQuizRouter(db *gorm.DB, router *gin.Engine) *userQuizRouter {
|
|
repository := repositories.NewUserQuizRepository(db)
|
|
quizRepostory := repositories.NewQuizRepository(db)
|
|
userquizRepository := repositories.NewUserQuizRepository(db)
|
|
userquizpaperRepository := repositories.NewUserQuizPaperRepository(db)
|
|
service := services.NewUserQuizService(repository, quizRepostory)
|
|
quizService := services.NewQuizService(quizRepostory)
|
|
userquizService := services.NewUserQuizService(userquizRepository, quizRepostory)
|
|
userquizpaperService := services.NewUserQuizPaperService(userquizpaperRepository, userquizRepository)
|
|
controller := controllers.NewUserQuizController(service, quizService, userquizpaperService)
|
|
|
|
return &userQuizRouter{
|
|
db: db,
|
|
repository: repository,
|
|
quizRepository: quizRepostory,
|
|
userquizpaperRepository: userquizpaperRepository,
|
|
userquizRepository: userquizRepository,
|
|
service: service,
|
|
quizService: quizService,
|
|
userquizpaperService: userquizpaperService,
|
|
userquizService: userquizService,
|
|
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)
|
|
group.PATCH("/:id", middleware.Auth("member"), r.controller.Answer)
|
|
}
|