product_find.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_m_api/consts"
  6. "youngee_m_api/model/http_model"
  7. "youngee_m_api/service"
  8. "youngee_m_api/util"
  9. )
  10. func WrapFindProductHandler(ctx *gin.Context) {
  11. handler := newFindProductHandler(ctx)
  12. BaseRun(handler)
  13. }
  14. func newFindProductHandler(ctx *gin.Context) *FindProductHandler {
  15. return &FindProductHandler{
  16. req: http_model.NewFindProductRequest(),
  17. resp: http_model.NewFindProductResponse(),
  18. ctx: ctx,
  19. }
  20. }
  21. type FindProductHandler struct {
  22. req *http_model.FindProductRequest
  23. resp *http_model.CommonResponse
  24. ctx *gin.Context
  25. }
  26. func (h *FindProductHandler) getRequest() interface{} {
  27. return h.req
  28. }
  29. func (h *FindProductHandler) getContext() *gin.Context {
  30. return h.ctx
  31. }
  32. func (h *FindProductHandler) getResponse() interface{} {
  33. return h.resp
  34. }
  35. func (h *FindProductHandler) run() {
  36. data := *&http_model.FindProductRequest{}
  37. data = *h.req
  38. res, err := service.Product.FindByID(h.ctx, data.ProductID)
  39. if err != nil {
  40. // 数据库查询失败,返回5001
  41. logrus.Errorf("[FindProductHandler] call FindByID err:%+v\n", err)
  42. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
  43. logrus.Info("FindProduct fail,req:%+v", h.req)
  44. return
  45. }
  46. h.resp.Data = res
  47. }
  48. func (h *FindProductHandler) checkParam() error {
  49. return nil
  50. }