product_find.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. log "github.com/sirupsen/logrus"
  10. )
  11. // WrapSendCodeHandler
  12. // @BasePath /youngee/m/
  13. // FindProduct godoc
  14. // @Summary findProduct 根据产品名称查询产品信息
  15. // @Schemes
  16. // @Description 根据产品名称查询产品信息
  17. // @Accept json
  18. // @Produce json
  19. // @Param Authorization header string true "登录TOKEN信息"
  20. // @Param req body http_model.FindProductRequest true "发送产品id请求参数结构体"
  21. // @Success 200 {object} http_model.CommonResponse{data=http_model.FindProductData} "查询对应产品返回相应结构体"
  22. // @Router /product/find [post]
  23. func WrapFindProductHandler(ctx *gin.Context) {
  24. handler := newFindProductHandler(ctx)
  25. baseRun(handler)
  26. }
  27. func newFindProductHandler(ctx *gin.Context) *FindProductHandler {
  28. return &FindProductHandler{
  29. req: http_model.NewFindProductRequest(),
  30. resp: http_model.NewFindProductResponse(),
  31. ctx: ctx,
  32. }
  33. }
  34. type FindProductHandler struct {
  35. req *http_model.FindProductRequest
  36. resp *http_model.CommonResponse
  37. ctx *gin.Context
  38. }
  39. func (h *FindProductHandler) getRequest() interface{} {
  40. return h.req
  41. }
  42. func (h *FindProductHandler) getContext() *gin.Context {
  43. return h.ctx
  44. }
  45. func (h *FindProductHandler) getResponse() interface{} {
  46. return h.resp
  47. }
  48. func (h *FindProductHandler) run() {
  49. data := *&http_model.FindProductRequest{}
  50. data = *h.req
  51. res, err := service.Product.FindByID(h.ctx, data.ProductID)
  52. if err != nil {
  53. // 数据库查询失败,返回5001
  54. logrus.Errorf("[FindProductHandler] call FindByID err:%+v\n", err)
  55. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
  56. log.Info("FindProduct fail,req:%+v", h.req)
  57. return
  58. }
  59. h.resp.Data = res
  60. }
  61. func (h *FindProductHandler) checkParam() error {
  62. return nil
  63. }