package handler import ( "youngee_b_api/consts" "youngee_b_api/model/http_model" "youngee_b_api/service" "youngee_b_api/util" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus" ) // WrapSendCodeHandler // @BasePath /youngee/m/ // FindProduct godoc // @Summary findProduct 根据产品名称查询产品信息 // @Schemes // @Description 根据产品名称查询产品信息 // @Accept json // @Produce json // @Param Authorization header string true "登录TOKEN信息" // @Param req body http_model.FindProductRequest true "发送产品id请求参数结构体" // @Success 200 {object} http_model.CommonResponse{data=http_model.FindProductData} "查询对应产品返回相应结构体" // @Router /product/find [post] func WrapFindProductHandler(ctx *gin.Context) { handler := newFindProductHandler(ctx) baseRun(handler) } func newFindProductHandler(ctx *gin.Context) *FindProductHandler { return &FindProductHandler{ req: http_model.NewFindProductRequest(), resp: http_model.NewFindProductResponse(), ctx: ctx, } } type FindProductHandler struct { req *http_model.FindProductRequest resp *http_model.CommonResponse ctx *gin.Context } func (h *FindProductHandler) getRequest() interface{} { return h.req } func (h *FindProductHandler) getContext() *gin.Context { return h.ctx } func (h *FindProductHandler) getResponse() interface{} { return h.resp } func (h *FindProductHandler) run() { data := *&http_model.FindProductRequest{} data = *h.req res, err := service.Product.FindByID(h.ctx, data.ProductID) if err != nil { // 数据库查询失败,返回5001 logrus.Errorf("[FindProductHandler] call FindByID err:%+v\n", err) util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "") log.Info("FindProduct fail,req:%+v", h.req) return } h.resp.Data = res } func (h *FindProductHandler) checkParam() error { return nil }