woj-server/internal/api/problem/handler.go

47 lines
1.4 KiB
Go
Raw Normal View History

2022-09-26 16:13:31 +08:00
package problem
import (
2023-07-15 16:19:49 +08:00
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
2023-07-14 21:47:11 +08:00
"git.0x7f.app/WOJ/woj-server/internal/service/problem"
"git.0x7f.app/WOJ/woj-server/internal/service/storage"
"git.0x7f.app/WOJ/woj-server/internal/service/task"
2023-07-15 16:19:49 +08:00
"git.0x7f.app/WOJ/woj-server/internal/web/jwt"
2022-09-26 16:13:31 +08:00
"github.com/gin-gonic/gin"
2023-07-15 16:19:49 +08:00
"github.com/samber/do"
2022-09-26 16:13:31 +08:00
"go.uber.org/zap"
)
var _ Handler = (*handler)(nil)
type Handler interface {
Details(c *gin.Context)
2022-09-26 16:13:31 +08:00
Search(c *gin.Context)
Update(c *gin.Context)
Upload(c *gin.Context)
2023-08-11 15:39:15 +08:00
CreateVersion(c *gin.Context)
2022-09-26 16:13:31 +08:00
}
type handler struct {
log *zap.Logger
2023-07-15 16:19:49 +08:00
jwtService jwt.Service
problemService problem.Service
taskService task.Service
storageService storage.Service
2022-09-26 16:13:31 +08:00
}
2023-07-15 16:19:49 +08:00
func RouteRegister(rg *gin.RouterGroup, i *do.Injector) {
2022-09-26 16:13:31 +08:00
app := &handler{
2023-07-15 16:19:49 +08:00
log: do.MustInvoke[log.Service](i).GetLogger("api.problem"),
jwtService: do.MustInvoke[jwt.Service](i),
problemService: do.MustInvoke[problem.Service](i),
taskService: do.MustInvoke[task.Service](i),
storageService: do.MustInvoke[storage.Service](i),
2022-09-26 16:13:31 +08:00
}
2023-07-15 16:19:49 +08:00
rg.POST("/search", app.Search)
rg.POST("/details", app.jwtService.Handler(false), app.Details)
rg.POST("/update", app.jwtService.Handler(true), app.Update)
rg.POST("/upload", app.jwtService.Handler(true), app.Upload)
rg.POST("/create_version", app.jwtService.Handler(true), app.CreateVersion)
2022-09-26 16:13:31 +08:00
}