cslms-api/internal/routers/userquizpaper.go

71 lines
2.4 KiB
Go
Raw Normal View History

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 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
quizRepository repositories.QuizRepository
service services.UserQuizPaperService
controller controllers.UserQuizPaperController
2023-12-27 17:31:49 +09:00
// 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)
2024-02-19 22:43:31 +09:00
service := services.NewUserQuizPaperService(repository, userQuizRepository)
quizService := services.NewQuizService(quizRepository)
2023-12-27 17:31:49 +09:00
quizPaperService := services.NewQuizPaperService(quizPaperRepository)
userService := services.NewUserService(userRepository, tokenRepository)
userQuizService := services.NewUserQuizService(userQuizRepository, quizRepository)
controller := controllers.NewUserQuizPaperController(service, quizService, quizPaperService, userQuizService, userService)
2023-12-27 17:31:49 +09:00
return &userQuizPaperRouter{
db: db,
repository: repository,
quizRepository: quizRepository,
service: service,
controller: controller,
router: router,
2023-12-27 17:31:49 +09:00
}
}
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)
}