withdrawalRecords.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/pack"
  11. "youngee_m_api/util"
  12. )
  13. func WrapWithdrawalRecordsHandler(ctx *gin.Context) {
  14. handler := newWithdrawalRecordsHandler(ctx)
  15. BaseRun(handler)
  16. }
  17. type WithdrawalRecordsHandler struct {
  18. ctx *gin.Context
  19. req *http_model.WithdrawalRecordsRequest
  20. resp *http_model.CommonResponse
  21. }
  22. func (w WithdrawalRecordsHandler) getContext() *gin.Context {
  23. return w.ctx
  24. }
  25. func (w WithdrawalRecordsHandler) getResponse() interface{} {
  26. return w.resp
  27. }
  28. func (w WithdrawalRecordsHandler) getRequest() interface{} {
  29. return w.req
  30. }
  31. func (w WithdrawalRecordsHandler) run() {
  32. condition := pack.HttpWithdrawRecordsRequestToCondition(w.req)
  33. data, err := db.GetWithdrawRecords(w.ctx, w.req.PageSize, w.req.PageNum, w.req, condition)
  34. if err != nil {
  35. logrus.WithContext(w.ctx).Errorf("[WithdrawalRecordsHandler] error GetWithdrawRecords, err:%+v", err)
  36. util.HandlerPackErrorResp(w.resp, consts.ErrorInternal, consts.DefaultToast)
  37. return
  38. }
  39. w.resp.Data = data
  40. }
  41. func (w WithdrawalRecordsHandler) checkParam() error {
  42. var errs []error
  43. if w.req.PageNum < 0 || w.req.PageSize <= 0 {
  44. errs = append(errs, errors.New("page param error"))
  45. }
  46. w.req.PageNum--
  47. if len(errs) != 0 {
  48. return fmt.Errorf("check param errs:%+v", errs)
  49. }
  50. return nil
  51. }
  52. func newWithdrawalRecordsHandler(ctx *gin.Context) *WithdrawalRecordsHandler {
  53. return &WithdrawalRecordsHandler{
  54. ctx: ctx,
  55. req: http_model.NewWithdrawalRecordsRequest(),
  56. resp: http_model.NewWithdrawalRecordsResponse(),
  57. }
  58. }