68 lines
2.2 KiB
Go
68 lines
2.2 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 InitUserQuizPaperRouter(db *gorm.DB, router *gin.Engine) {
|
||
|
r := NewUserQuizPaperRouter(db, router)
|
||
|
r.SetUserQuizPaperRouter()
|
||
|
}
|
||
|
|
||
|
type UserQuizPaperRouter interface {
|
||
|
SetRouter(db *gorm.DB, router *gin.Engine)
|
||
|
}
|
||
|
|
||
|
type userQuizPaperRouter struct {
|
||
|
db *gorm.DB
|
||
|
repository repositories.UserQuizPaperRepository
|
||
|
service services.UserQuizPaperService
|
||
|
controller controllers.UserQuizPaperController
|
||
|
// quizPaperRepository repositories.QuizPaperRepository
|
||
|
// userRepository repositories.UserRepository
|
||
|
|
||
|
// quizPaperService services.QuizPaperService
|
||
|
// userService services.UserService
|
||
|
|
||
|
router *gin.Engine
|
||
|
}
|
||
|
|
||
|
func NewUserQuizPaperRouter(db *gorm.DB, router *gin.Engine) *userQuizPaperRouter {
|
||
|
repository := repositories.NewUserQuizPaperRepository(db)
|
||
|
quizRepository := repositories.NewQuizRepository(db)
|
||
|
quizPaperRepository := repositories.NewQuizPaperRepository(db)
|
||
|
tokenRepository := repositories.NewTokenRepository(db)
|
||
|
userRepository := repositories.NewUserRepository(db)
|
||
|
userQuizRepository := repositories.NewUserQuizRepository(db)
|
||
|
|
||
|
service := services.NewUserQuizPaperService(repository)
|
||
|
quizPaperService := services.NewQuizPaperService(quizPaperRepository)
|
||
|
userService := services.NewUserService(userRepository, tokenRepository)
|
||
|
userQuizService := services.NewUserQuizService(userQuizRepository, quizRepository)
|
||
|
|
||
|
controller := controllers.NewUserQuizPaperController(service, userService, quizPaperService, userQuizService)
|
||
|
|
||
|
return &userQuizPaperRouter{
|
||
|
db: db,
|
||
|
repository: repository,
|
||
|
service: service,
|
||
|
controller: controller,
|
||
|
router: router,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *userQuizPaperRouter) SetUserQuizPaperRouter() {
|
||
|
group := r.router.Group("/userquizpaper")
|
||
|
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("admin"), r.controller.Patch)
|
||
|
}
|