account_info.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package handler
  2. import (
  3. "errors"
  4. "github.com/gin-gonic/gin"
  5. "github.com/sirupsen/logrus"
  6. "youngee_m_api/consts"
  7. "youngee_m_api/model/http_model"
  8. "youngee_m_api/pack"
  9. "youngee_m_api/service"
  10. "youngee_m_api/util"
  11. )
  12. func WrapAccountInfoHandler(ctx *gin.Context) {
  13. handler := newAccountInfoHandler(ctx)
  14. BaseRun(handler)
  15. }
  16. type accountHandler struct {
  17. ctx *gin.Context
  18. req *http_model.AccountInfoRequest
  19. resp *http_model.CommonResponse
  20. }
  21. func newAccountInfoHandler(ctx *gin.Context) *accountHandler {
  22. return &accountHandler{
  23. ctx: ctx,
  24. req: http_model.NewAccountInfoRequset(),
  25. resp: http_model.NewAccountInfoResponse(),
  26. }
  27. }
  28. func (a accountHandler) getContext() *gin.Context {
  29. return a.ctx
  30. }
  31. func (a accountHandler) getResponse() interface{} {
  32. return a.resp
  33. }
  34. func (a accountHandler) getRequest() interface{} {
  35. return a.req
  36. }
  37. func (a accountHandler) run() {
  38. conditions := pack.HttpAccountInfoRequestToCondition(a.req)
  39. data, err := service.User.AccountInfo(a.ctx, a.req.PageSize, a.req.PageNum, conditions)
  40. if err != nil {
  41. logrus.WithContext(a.ctx).Errorf("[WrapAccountInfoHandler] error AccountInfo, err:%+v", err)
  42. util.HandlerPackErrorResp(a.resp, consts.ErrorInternal, consts.DefaultToast)
  43. return
  44. }
  45. a.resp.Data = data
  46. }
  47. func (a accountHandler) checkParam() error {
  48. var errs []error
  49. if a.req.PageNum < 0 || a.req.PageSize <= 0 {
  50. errs = append(errs, errors.New("page param error"))
  51. }
  52. a.req.PageNum--
  53. return nil
  54. }