cslms-api/internal/routers/userquiz.go

70 lines
2.6 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 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 {
2024-02-19 22:43:31 +09:00
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
2023-12-27 17:31:49 +09:00
}
func NewUserQuizRouter(db *gorm.DB, router *gin.Engine) *userQuizRouter {
repository := repositories.NewUserQuizRepository(db)
quizRepostory := repositories.NewQuizRepository(db)
2024-02-19 22:43:31 +09:00
userquizRepository := repositories.NewUserQuizRepository(db)
userquizpaperRepository := repositories.NewUserQuizPaperRepository(db)
2023-12-27 17:31:49 +09:00
service := services.NewUserQuizService(repository, quizRepostory)
2024-02-19 22:43:31 +09:00
quizService := services.NewQuizService(quizRepostory)
userquizService := services.NewUserQuizService(userquizRepository, quizRepostory)
userquizpaperService := services.NewUserQuizPaperService(userquizpaperRepository, userquizRepository)
controller := controllers.NewUserQuizController(service, quizService, userquizpaperService)
2023-12-27 17:31:49 +09:00
return &userQuizRouter{
2024-02-19 22:43:31 +09:00
db: db,
repository: repository,
quizRepository: quizRepostory,
userquizpaperRepository: userquizpaperRepository,
userquizRepository: userquizRepository,
service: service,
quizService: quizService,
userquizpaperService: userquizpaperService,
userquizService: userquizService,
controller: controller,
router: router,
2023-12-27 17:31:49 +09:00
}
}
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)
2024-02-19 22:43:31 +09:00
group.PATCH("/:id", middleware.Auth("member"), r.controller.Answer)
2023-12-27 17:31:49 +09:00
}