product_findAll.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. log "github.com/sirupsen/logrus"
  6. "youngee_m_api/consts"
  7. "youngee_m_api/db"
  8. "youngee_m_api/model/http_model"
  9. "youngee_m_api/service"
  10. "youngee_m_api/util"
  11. )
  12. func WrapFindEnterpriseAllProductHandler(ctx *gin.Context) {
  13. handler := newFindEnterpriseAllProductHandler(ctx)
  14. BaseRun(handler)
  15. }
  16. func newFindEnterpriseAllProductHandler(ctx *gin.Context) *FindAllProductHandler {
  17. return &FindAllProductHandler{
  18. req: http_model.NewFindAllProductRequest(),
  19. resp: http_model.NewFindAllProductResponse(),
  20. ctx: ctx,
  21. }
  22. }
  23. type FindAllProductHandler struct {
  24. req *http_model.FindAllProductRequest
  25. resp *http_model.CommonResponse
  26. ctx *gin.Context
  27. }
  28. func (h *FindAllProductHandler) getRequest() interface{} {
  29. return h.req
  30. }
  31. func (h *FindAllProductHandler) getContext() *gin.Context {
  32. return h.ctx
  33. }
  34. func (h *FindAllProductHandler) getResponse() interface{} {
  35. return h.resp
  36. }
  37. func (h *FindAllProductHandler) run() {
  38. enterpriseID := db.GetEnterpriseIDByUserID(h.ctx, h.req.UserID)
  39. if enterpriseID == "" {
  40. // 数据库查询失败,返回5001
  41. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
  42. log.Info("FindAllProduct fail,req:%+v", h.req)
  43. return
  44. }
  45. res, err := service.Product.FindAll(h.ctx, enterpriseID)
  46. if err != nil {
  47. // 数据库查询失败,返回5001
  48. logrus.Errorf("[FindAllProductHandler] call FindAll err:%+v\n", err)
  49. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
  50. log.Info("FindAllProduct fail,req:%+v", h.req)
  51. return
  52. }
  53. h.resp.Data = res
  54. }
  55. func (h *FindAllProductHandler) checkParam() error {
  56. return nil
  57. }