From 608bdbcc2797be89e6df87ca0ef701e7889f401d Mon Sep 17 00:00:00 2001 From: yokowu <18836617@qq.com> Date: Tue, 22 Jul 2025 18:46:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=B4=E5=83=8F=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/user/repo/user.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/internal/user/repo/user.go b/backend/internal/user/repo/user.go index 908c0db..29d831d 100644 --- a/backend/internal/user/repo/user.go +++ b/backend/internal/user/repo/user.go @@ -347,9 +347,23 @@ func (r *UserRepo) OAuthLogin(ctx context.Context, platform consts.UserPlatform, if err != nil { return nil, errcode.ErrNotInvited.Wrap(err) } + if ui.AvatarURL != req.AvatarURL { + if err = entx.WithTx(ctx, r.db, func(tx *db.Tx) error { + return r.updateAvatar(ctx, tx, ui, req.AvatarURL) + }); err != nil { + return nil, err + } + } return ui.Edges.User, nil } +func (r *UserRepo) updateAvatar(ctx context.Context, tx *db.Tx, ui *db.UserIdentity, avatar string) error { + if err := tx.UserIdentity.UpdateOneID(ui.ID).SetAvatarURL(avatar).Exec(ctx); err != nil { + return err + } + return tx.User.UpdateOneID(ui.UserID).SetAvatarURL(avatar).Exec(ctx) +} + func (r *UserRepo) SignUpOrIn(ctx context.Context, platform consts.UserPlatform, req *domain.OAuthUserInfo) (*db.User, error) { var u *db.User err := entx.WithTx(ctx, r.db, func(tx *db.Tx) error { @@ -359,6 +373,11 @@ func (r *UserRepo) SignUpOrIn(ctx context.Context, platform consts.UserPlatform, First(ctx) if err == nil { u = ui.Edges.User + if ui.AvatarURL != req.AvatarURL { + if err = r.updateAvatar(ctx, tx, ui, req.AvatarURL); err != nil { + return err + } + } return nil } if !db.IsNotFound(err) {