findAllProduct.go 1.3 KB

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