update_user_info.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_m_api/consts"
  6. "youngee_m_api/db"
  7. "youngee_m_api/model/http_model"
  8. "youngee_m_api/util"
  9. )
  10. func WrapUpdateUserInfoHandler(ctx *gin.Context) {
  11. handler := newUpdateUserInfoHandler(ctx)
  12. BaseRun(handler)
  13. }
  14. func newUpdateUserInfoHandler(ctx *gin.Context) *UpdateUserInfoHandler {
  15. return &UpdateUserInfoHandler{
  16. req: http_model.NewUpdateUserInfoRequest(),
  17. resp: http_model.NewUpdateUserInfoResponse(),
  18. ctx: ctx,
  19. }
  20. }
  21. type UpdateUserInfoHandler struct {
  22. req *http_model.UpdateUserInfoRequest
  23. resp *http_model.CommonResponse
  24. ctx *gin.Context
  25. }
  26. func (u UpdateUserInfoHandler) getContext() *gin.Context {
  27. return u.ctx
  28. }
  29. func (u UpdateUserInfoHandler) getResponse() interface{} {
  30. return u.resp
  31. }
  32. func (u UpdateUserInfoHandler) getRequest() interface{} {
  33. return u.req
  34. }
  35. func (u UpdateUserInfoHandler) run() {
  36. toast, err := db.UpdateUserInfo(u.ctx, u.req)
  37. if err != nil {
  38. // 数据库查询失败,返回5001
  39. logrus.Errorf("[UpdateUserInfoHandler] call UpdateUserInfo err:%+v\n", err)
  40. util.HandlerPackErrorResp(u.resp, consts.ErrorInternal, "")
  41. logrus.Info("UpdateUserInfoHandler fail,req:%+v", u.req)
  42. return
  43. }
  44. if toast == "更新成功" {
  45. u.resp.Message = "更新成功"
  46. } else {
  47. u.resp.Message = "更新失败"
  48. }
  49. }
  50. func (u UpdateUserInfoHandler) checkParam() error {
  51. return nil
  52. }