userinfo_update.go 1.5 KB

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