71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package routes
|
|
|
|
import (
|
|
"exam_registration/internal/handler"
|
|
"exam_registration/internal/middleware"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SetupRouter(r *gin.Engine) {
|
|
userHandler := handler.NewUserHandler()
|
|
examHandler := handler.NewExamHandler()
|
|
registrationHandler := handler.NewRegistrationHandler()
|
|
noticeHandler := handler.NewNoticeHandler()
|
|
scoreHandler := handler.NewScoreHandler()
|
|
|
|
// 公开路由
|
|
public := r.Group("/api")
|
|
{
|
|
// 用户认证
|
|
public.POST("/login", userHandler.Login)
|
|
public.POST("/register", userHandler.Register)
|
|
|
|
// 考试列表(公开查询)
|
|
public.GET("/exams", examHandler.GetExamList)
|
|
public.GET("/exams/:id", examHandler.GetExamByID)
|
|
|
|
// 通知列表(公开查询)
|
|
public.GET("/notices", noticeHandler.GetNoticeList)
|
|
public.GET("/notices/:id", noticeHandler.GetNoticeByID)
|
|
}
|
|
|
|
// 需要认证的路由
|
|
protected := r.Group("/api")
|
|
protected.Use(middleware.JWT())
|
|
{
|
|
// 用户相关
|
|
protected.GET("/user/info", userHandler.GetUserInfo)
|
|
protected.PUT("/user/info", userHandler.UpdateUserInfo)
|
|
|
|
// 考试管理(管理员)
|
|
admin := protected.Group("")
|
|
{
|
|
admin.POST("/exams", examHandler.CreateExam)
|
|
admin.PUT("/exams/:id", examHandler.UpdateExam)
|
|
admin.DELETE("/exams/:id", examHandler.DeleteExam)
|
|
}
|
|
|
|
// 报名管理
|
|
protected.POST("/registrations", registrationHandler.CreateRegistration)
|
|
protected.GET("/registrations", registrationHandler.GetRegistrationList)
|
|
protected.PUT("/registrations/:id", registrationHandler.UpdateRegistration)
|
|
protected.DELETE("/registrations/:id", registrationHandler.DeleteRegistration)
|
|
|
|
// 报名审核(管理员)
|
|
protected.PUT("/registrations/:id/audit", registrationHandler.AuditRegistration)
|
|
|
|
// 通知管理(管理员)
|
|
protected.POST("/notices", noticeHandler.CreateNotice)
|
|
protected.PUT("/notices/:id", noticeHandler.UpdateNotice)
|
|
protected.DELETE("/notices/:id", noticeHandler.DeleteNotice)
|
|
|
|
// 成绩管理
|
|
protected.POST("/scores", scoreHandler.CreateScore)
|
|
protected.POST("/scores/batch", scoreHandler.BatchCreateScores)
|
|
protected.GET("/scores/exam/:exam_id", scoreHandler.GetScoreByUserAndExam)
|
|
protected.GET("/scores", scoreHandler.GetScoreList)
|
|
protected.PUT("/scores/:id/publish", scoreHandler.PublishScore)
|
|
protected.DELETE("/scores/:id", scoreHandler.DeleteScore)
|
|
}
|
|
}
|