product_findAll.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package handler
  2. import (
  3. "youngee_b_api/consts"
  4. "youngee_b_api/middleware"
  5. "youngee_b_api/model/http_model"
  6. "youngee_b_api/service"
  7. "youngee_b_api/util"
  8. "github.com/gin-gonic/gin"
  9. "github.com/sirupsen/logrus"
  10. log "github.com/sirupsen/logrus"
  11. )
  12. func WrapFindAllProductHandler(ctx *gin.Context) {
  13. handler := newFindAllProductHandler(ctx)
  14. baseRun(handler)
  15. }
  16. func newFindAllProductHandler(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. auth := middleware.GetSessionAuth(h.ctx)
  39. enterpriseID := auth.EnterpriseID
  40. res, err := service.Product.FindAll(h.ctx, enterpriseID)
  41. if err != nil {
  42. // 数据库查询失败,返回5001
  43. logrus.Errorf("[FindAllProductHandler] call FindAll err:%+v\n", err)
  44. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
  45. log.Info("FindAllProduct fail,req:%+v", h.req)
  46. return
  47. }
  48. // h.resp.Message = "查询成功"
  49. h.resp.Data = res
  50. }
  51. func (h *FindAllProductHandler) checkParam() error {
  52. return nil
  53. }