feat: 更新oauth name

This commit is contained in:
yokowu
2025-09-09 19:03:24 +08:00
parent 8cab46b785
commit aba7485c04

View File

@@ -423,6 +423,13 @@ func (r *UserRepo) OAuthLogin(ctx context.Context, platform consts.UserPlatform,
if ui.Edges.User.Status != consts.UserStatusActive {
return nil, errcode.ErrUserLock
}
if ui.Nickname != req.Name {
if err = entx.WithTx(ctx, r.db, func(tx *db.Tx) error {
return r.updateUsername(ctx, tx, ui, req.Name)
}); err != nil {
return nil, 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)
@@ -433,6 +440,13 @@ func (r *UserRepo) OAuthLogin(ctx context.Context, platform consts.UserPlatform,
return ui.Edges.User, nil
}
func (r *UserRepo) updateUsername(ctx context.Context, tx *db.Tx, ui *db.UserIdentity, name string) error {
if err := tx.UserIdentity.UpdateOneID(ui.ID).SetNickname(name).Exec(ctx); err != nil {
return err
}
return tx.User.UpdateOneID(ui.UserID).SetUsername(name).Exec(ctx)
}
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
@@ -452,6 +466,11 @@ func (r *UserRepo) SignUpOrIn(ctx context.Context, platform consts.UserPlatform,
if u.Status != consts.UserStatusActive {
return errcode.ErrUserLock
}
if ui.Nickname != req.Name {
if err = r.updateUsername(ctx, tx, ui, req.Name); err != nil {
return err
}
}
if ui.AvatarURL != req.AvatarURL {
if err = r.updateAvatar(ctx, tx, ui, req.AvatarURL); err != nil {
return err