90 lines
3.3 KiB
Go
90 lines
3.3 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 InitPaperRouter(db *gorm.DB, router *gin.Engine) {
|
||
|
r := NewPaperRouter(db, router)
|
||
|
r.SetPaperRouter()
|
||
|
}
|
||
|
|
||
|
type PaperRouter interface {
|
||
|
SetRouter(db *gorm.DB, router *gin.Engine)
|
||
|
}
|
||
|
|
||
|
type paperRouter struct {
|
||
|
db *gorm.DB
|
||
|
repository repositories.PaperRepository
|
||
|
paperQuizRepository repositories.PaperQuizRepository
|
||
|
quizRepository repositories.QuizRepository
|
||
|
quizPaperRepository repositories.QuizPaperRepository
|
||
|
userRepository repositories.UserRepository
|
||
|
userQuizRepository repositories.UserQuizRepository
|
||
|
service services.PaperService
|
||
|
paperQuizService services.PaperQuizService
|
||
|
quizService services.QuizService
|
||
|
quizPaperService services.QuizPaperService
|
||
|
userService services.UserService
|
||
|
userQuizService services.UserQuizService
|
||
|
controller controllers.PaperController
|
||
|
router *gin.Engine
|
||
|
}
|
||
|
|
||
|
func NewPaperRouter(db *gorm.DB, router *gin.Engine) *paperRouter {
|
||
|
repository := repositories.NewPaperRepository(db)
|
||
|
paperQuizRepository := repositories.NewPaperQuizRepository(db)
|
||
|
quizRepository := repositories.NewQuizRepository(db)
|
||
|
quizPaperRepository := repositories.NewQuizPaperRepository(db)
|
||
|
tokenRepository := repositories.NewTokenRepository(db)
|
||
|
userRepository := repositories.NewUserRepository(db)
|
||
|
userQuizRepository := repositories.NewUserQuizRepository(db)
|
||
|
|
||
|
service := services.NewPaperService(repository, paperQuizRepository)
|
||
|
paperQuizService := services.NewPaperQuizService(paperQuizRepository)
|
||
|
quizService := services.NewQuizService(quizRepository)
|
||
|
quizPaperService := services.NewQuizPaperService(quizPaperRepository)
|
||
|
userService := services.NewUserService(userRepository, tokenRepository)
|
||
|
userQuizService := services.NewUserQuizService(userQuizRepository, quizRepository)
|
||
|
|
||
|
controller := controllers.NewPaperController(service, paperQuizService, quizService, quizPaperService, userService, userQuizService)
|
||
|
|
||
|
return &paperRouter{
|
||
|
db: db,
|
||
|
repository: repository,
|
||
|
quizRepository: quizRepository,
|
||
|
quizPaperRepository: quizPaperRepository,
|
||
|
userRepository: userRepository,
|
||
|
userQuizRepository: userQuizRepository,
|
||
|
|
||
|
service: service,
|
||
|
paperQuizService: paperQuizService,
|
||
|
quizService: quizService,
|
||
|
quizPaperService: quizPaperService,
|
||
|
userService: userService,
|
||
|
userQuizService: userQuizService,
|
||
|
|
||
|
controller: controller,
|
||
|
|
||
|
router: router,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *paperRouter) SetPaperRouter() {
|
||
|
group := r.router.Group("/paper")
|
||
|
group.GET("", middleware.Auth("member"), r.controller.List)
|
||
|
group.GET("/:paper_id", middleware.Auth("member"), r.controller.Find)
|
||
|
group.PATCH("/:paper_id/start", middleware.Auth("member"), r.controller.Start)
|
||
|
group.PATCH("/:paper_id/finish", middleware.Auth("member"), r.controller.Finish)
|
||
|
|
||
|
group.GET("/:paper_id/quiz", middleware.Auth("member"), r.controller.QuizList)
|
||
|
group.GET("/:paper_id/quiz/:quiz_id", middleware.Auth("member"), r.controller.QuizFind)
|
||
|
group.PATCH("/:paper_id/quiz/:quiz_id/answer", middleware.Auth("member"), r.controller.QuizAnswer)
|
||
|
}
|