76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"git.hpds.cc/Component/logging"
|
|
"github.com/gin-gonic/gin"
|
|
"hpds_annotation/config"
|
|
"hpds_annotation/internal/proto"
|
|
"hpds_annotation/internal/service"
|
|
e "hpds_annotation/pkg/err"
|
|
)
|
|
|
|
type HandlerService struct {
|
|
AppConfig *config.WebConfig
|
|
Logger *logging.Logger
|
|
}
|
|
|
|
func NewHandlerService(cfg *config.WebConfig, logger *logging.Logger) *HandlerService {
|
|
return &HandlerService{
|
|
AppConfig: cfg,
|
|
Logger: logger,
|
|
}
|
|
}
|
|
|
|
func (s HandlerService) GetList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewEdgeService(s.Logger)
|
|
var req proto.ListRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if req.Size < 1 {
|
|
req.Size = 20
|
|
}
|
|
if req.Size > 1000 {
|
|
req.Size = 1000
|
|
}
|
|
if req.Page < 1 {
|
|
req.Page = 1
|
|
}
|
|
if err != nil {
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.GetList(c, req)
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) GetInfo(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewEdgeService(s.Logger)
|
|
var req proto.ListRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.GetInfo(c, req)
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) LabelSubmit(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewEdgeService(s.Logger)
|
|
var req proto.LabelRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.LabelSubmit(c, req)
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) CaptureSubmit(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewEdgeService(s.Logger)
|
|
var req proto.CaptureRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.CaptureSubmit(c, req)
|
|
return
|
|
}
|