product_find.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package handler
  2. import (
  3. "youngee_b_api/consts"
  4. "youngee_b_api/model/http_model"
  5. "youngee_b_api/service"
  6. "youngee_b_api/util"
  7. "github.com/gin-gonic/gin"
  8. "github.com/sirupsen/logrus"
  9. )
  10. func WrapFindProductHandler(ctx *gin.Context) {
  11. handler := newFindProductHandler(ctx)
  12. baseRun(handler)
  13. }
  14. func newFindProductHandler(ctx *gin.Context) *FindProductHandler {
  15. return &FindProductHandler{
  16. req: http_model.NewFindProductRequest(),
  17. resp: http_model.NewFindProductResponse(),
  18. ctx: ctx,
  19. }
  20. }
  21. type FindProductHandler struct {
  22. req *http_model.FindProductRequest
  23. resp *http_model.CommonResponse
  24. ctx *gin.Context
  25. }
  26. func (h *FindProductHandler) getRequest() interface{} {
  27. return h.req
  28. }
  29. func (h *FindProductHandler) getContext() *gin.Context {
  30. return h.ctx
  31. }
  32. func (h *FindProductHandler) getResponse() interface{} {
  33. return h.resp
  34. }
  35. func (h *FindProductHandler) run() {
  36. data := *&http_model.FindProductRequest{}
  37. data = *h.req
  38. res, err := service.Product.FindByID(h.ctx, data.ProductID)
  39. if err != nil {
  40. // 数据库查询失败,返回5001
  41. logrus.Errorf("[FindProductHandler] call Find err:%+v\n", err)
  42. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
  43. return
  44. }
  45. h.resp.Data = res
  46. }
  47. func (h *FindProductHandler) checkParam() error {
  48. return nil
  49. }