2022-09-26 16:13:31 +08:00
|
|
|
package problem
|
|
|
|
|
|
|
|
import (
|
2022-10-20 16:50:19 +08:00
|
|
|
"github.com/WHUPRJ/woj-server/internal/global"
|
2022-09-26 16:13:31 +08:00
|
|
|
"github.com/WHUPRJ/woj-server/internal/service/problem"
|
2022-10-23 17:29:35 +08:00
|
|
|
"github.com/WHUPRJ/woj-server/internal/service/storage"
|
|
|
|
"github.com/WHUPRJ/woj-server/internal/service/task"
|
2022-09-26 16:13:31 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ Handler = (*handler)(nil)
|
|
|
|
|
|
|
|
type Handler interface {
|
2022-10-22 17:38:39 +08:00
|
|
|
Details(c *gin.Context)
|
2022-09-26 16:13:31 +08:00
|
|
|
Search(c *gin.Context)
|
2022-10-22 17:38:39 +08:00
|
|
|
Update(c *gin.Context)
|
2022-10-23 17:29:35 +08:00
|
|
|
Upload(c *gin.Context)
|
2022-09-26 16:13:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type handler struct {
|
|
|
|
log *zap.Logger
|
|
|
|
jwtService global.JwtService
|
2022-10-22 17:38:39 +08:00
|
|
|
problemService problem.Service
|
2022-10-23 17:29:35 +08:00
|
|
|
taskService task.Service
|
|
|
|
storageService storage.Service
|
2022-09-26 16:13:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func RouteRegister(g *global.Global, group *gin.RouterGroup) {
|
|
|
|
app := &handler{
|
|
|
|
log: g.Log,
|
|
|
|
jwtService: g.Jwt,
|
2022-10-22 17:38:39 +08:00
|
|
|
problemService: problem.NewService(g),
|
2022-10-23 17:29:35 +08:00
|
|
|
taskService: task.NewService(g),
|
|
|
|
storageService: storage.NewService(g),
|
2022-09-26 16:13:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
group.POST("/search", app.Search)
|
2022-10-23 17:29:35 +08:00
|
|
|
group.POST("/details", app.jwtService.Handler(false), app.Details)
|
2022-10-22 17:38:39 +08:00
|
|
|
group.POST("/update", app.jwtService.Handler(true), app.Update)
|
2022-10-23 17:29:35 +08:00
|
|
|
group.POST("/upload", app.jwtService.Handler(true), app.Upload)
|
|
|
|
group.POST("/create_version", app.jwtService.Handler(true), app.CreateVersion)
|
2022-09-26 16:13:31 +08:00
|
|
|
}
|