product_findAll.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. )
  11. func WrapFindAllProductHandler(ctx *gin.Context) {
  12. handler := newFindAllProductHandler(ctx)
  13. baseRun(handler)
  14. }
  15. func newFindAllProductHandler(ctx *gin.Context) *FindAllProductHandler {
  16. return &FindAllProductHandler{
  17. req: http_model.NewFindAllProductRequest(),
  18. resp: http_model.NewFindAllProductResponse(),
  19. ctx: ctx,
  20. }
  21. }
  22. type FindAllProductHandler struct {
  23. req *http_model.FindAllProductRequest
  24. resp *http_model.CommonResponse
  25. ctx *gin.Context
  26. }
  27. func (h *FindAllProductHandler) getRequest() interface{} {
  28. return h.req
  29. }
  30. func (h *FindAllProductHandler) getContext() *gin.Context {
  31. return h.ctx
  32. }
  33. func (h *FindAllProductHandler) getResponse() interface{} {
  34. return h.resp
  35. }
  36. func (h *FindAllProductHandler) run() {
  37. auth := middleware.GetSessionAuth(h.ctx)
  38. enterpriseID := auth.EnterpriseID
  39. res, err := service.Product.FindAll(h.ctx, enterpriseID)
  40. if err != nil {
  41. // 数据库查询失败,返回5001
  42. logrus.Errorf("[FindAllProductHandler] call FindAll err:%+v\n", err)
  43. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
  44. return
  45. }
  46. h.resp.Data = res
  47. }
  48. func (h *FindAllProductHandler) checkParam() error {
  49. return nil
  50. }