product_findAll.go 1.5 KB

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