getSelectionInfo.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package handler
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "github.com/sirupsen/logrus"
  7. "youngee_m_api/consts"
  8. "youngee_m_api/db"
  9. "youngee_m_api/model/http_model"
  10. "youngee_m_api/util"
  11. )
  12. func WrapGetSelectionInfoHandler(ctx *gin.Context) {
  13. handler := newGetSelectionInfoHandler(ctx)
  14. BaseRun(handler)
  15. }
  16. type GetSelectionInfoHandler struct {
  17. ctx *gin.Context
  18. req *http_model.GetSelectionInfoRequest
  19. resp *http_model.CommonResponse
  20. }
  21. func (g GetSelectionInfoHandler) getContext() *gin.Context {
  22. return g.ctx
  23. }
  24. func (g GetSelectionInfoHandler) getResponse() interface{} {
  25. return g.resp
  26. }
  27. func (g GetSelectionInfoHandler) getRequest() interface{} {
  28. return g.req
  29. }
  30. func (g GetSelectionInfoHandler) run() {
  31. //condition := pack.HttpRechargeRecordsRequestToCondition(g.req)
  32. data, err := db.GetSelectionInfo(g.ctx, g.req)
  33. if err != nil {
  34. // 数据库查询失败,返回5001
  35. logrus.Errorf("[GetSelectionInfoHandler] call GetSelectionInfo err:%+v\n", err)
  36. util.HandlerPackErrorResp(g.resp, consts.ErrorInternal, "")
  37. logrus.Info("GetSelectionInfo fail,req:%+v", g.req)
  38. return
  39. }
  40. g.resp.Data = data
  41. }
  42. func (g GetSelectionInfoHandler) checkParam() error {
  43. var errs []error
  44. if g.req.PageNum < 0 || g.req.PageSize <= 0 {
  45. errs = append(errs, errors.New("page param error"))
  46. }
  47. g.req.PageNum--
  48. if len(errs) != 0 {
  49. return fmt.Errorf("check param errs:%+v", errs)
  50. }
  51. return nil
  52. }
  53. func newGetSelectionInfoHandler(ctx *gin.Context) *GetSelectionInfoHandler {
  54. return &GetSelectionInfoHandler{
  55. ctx: ctx,
  56. req: http_model.NewGetSelectionInfoRequest(),
  57. resp: http_model.NewGetSelectionInfoResponse(),
  58. }
  59. }