From da73347231dca83348962011896fc6026b4e28c5 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 28 Dec 2021 20:28:01 +0800 Subject: [PATCH] tidy code --- internal/rpc/auth/auth.go | 3 +++ internal/rpc/user/user.go | 3 +++ pkg/common/db/mysql_model/im_mysql_model/user_model.go | 7 +------ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/rpc/auth/auth.go b/internal/rpc/auth/auth.go index 70ebfcbc0..d0137d012 100644 --- a/internal/rpc/auth/auth.go +++ b/internal/rpc/auth/auth.go @@ -22,6 +22,9 @@ func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) log.NewInfo(req.OperationID, "UserRegister args ", req.String()) var user imdb.User utils.CopyStructFields(&user, req.UserInfo) + if req.UserInfo.Birth != 0 { + user.Birth = utils.UnixSecondToTime(req.UserInfo.Birth) + } err := imdb.UserRegister(user) if err != nil { log.NewError(req.OperationID, "UserRegister failed ", err.Error(), user) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index e0bb07d3c..ad480d6db 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -214,6 +214,9 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI var user imdb.User utils.CopyStructFields(&user, req.UserInfo) + if req.UserInfo.Birth != 0 { + user.Birth = utils.UnixSecondToTime(req.UserInfo.Birth) + } err := imdb.UpdateUserInfo(user) if err != nil { log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), user) diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go index 376a4b267..01ca6d593 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -33,9 +33,6 @@ func UserRegister(user User) error { return err } user.CreateTime = time.Now() - if user.Birth != 0 { - user.Birth = utils.UnixSecondToTime(user.Birth) - } err = dbConn.Table("user").Create(&user).Error if err != nil { @@ -83,9 +80,7 @@ func UpdateUserInfo(user User) error { if err != nil { return err } - if user.Birth != 0 { - user.Birth = utils.UnixSecondToTime(user.Birth) - } + err = dbConn.Table("user").Where("user_id=?", user.UserID).Update(&user).Error return err }