12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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"
- )
- 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 Find err:%+v\n", err)
- util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
- return
- }
- h.resp.Data = res
- }
- func (h *FindProductHandler) checkParam() error {
- return nil
- }
|