annotation/internal/handler/index.go

67 lines
1.6 KiB
Go
Raw Normal View History

2023-05-12 16:53:21 +08:00
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 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
}