Skip to content

Commit

Permalink
fix(tiphereth): sync pull account on linking
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Mar 13, 2024
1 parent ca5b399 commit 699263b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/sephirah/internal/biz/bizangela/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewPullAccountTopic(
if err != nil {
return err
}
err = a.repo.UpdateAccount(ctx, modeltiphereth.Account{
err = a.repo.UpsertAccount(ctx, modeltiphereth.Account{
ID: info.ID,
Platform: info.Platform,
PlatformAccountID: info.PlatformAccountID,
Expand Down
2 changes: 1 addition & 1 deletion app/sephirah/internal/biz/bizangela/angela.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type AngelaBase struct {
}

type AngelaRepo interface {
UpdateAccount(context.Context, modeltiphereth.Account) error
UpsertAccount(context.Context, modeltiphereth.Account) error
UpsertAppInfo(context.Context, *modelgebura.AppInfo, *modelgebura.AppInfo) error
UpsertAppInfos(context.Context, []*modelgebura.AppInfo) error
AccountPurchaseAppInfos(context.Context, model.InternalID, []model.InternalID) error
Expand Down
13 changes: 7 additions & 6 deletions app/sephirah/internal/biz/biztiphereth/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ func (t *Tiphereth) LinkAccount(
return nil, pb.ErrorErrorReasonUnspecified("%s", err)
}
a.ID = id
a.ID, err = t.repo.LinkAccount(ctx, a, claims.UserID)
if err != nil {
return nil, pb.ErrorErrorReasonUnspecified("%s", err.Error())
}
if err = t.pullAccount.Publish(ctx, modeltiphereth.PullAccountInfo{
if err = t.pullAccount.LocalCall(ctx, modeltiphereth.PullAccountInfo{
ID: a.ID,
Platform: a.Platform,
PlatformAccountID: a.PlatformAccountID,
}); err != nil {
logger.Errorf("Publish PullAccountInfo failed %s", err.Error())
logger.Errorf("PullAccountInfo failed %s", err.Error())
return nil, pb.ErrorErrorReasonUnspecified("Get Account Info failed, %s", err.Error())
}
a.ID, err = t.repo.LinkAccount(ctx, a, claims.UserID)
if err != nil {
return nil, pb.ErrorErrorReasonUnspecified("%s", err.Error())
}
return &a, nil
}
Expand Down
19 changes: 13 additions & 6 deletions app/sephirah/internal/data/angela.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,22 @@ func NewAngelaRepo(data *Data) bizangela.AngelaRepo {
}
}

func (a *angelaRepo) UpdateAccount(ctx context.Context, acc modeltiphereth.Account) error {
return a.data.db.Account.Update().Where(
account.IDEQ(acc.ID),
account.PlatformEQ(acc.Platform),
account.PlatformAccountIDEQ(acc.PlatformAccountID),
).
func (a *angelaRepo) UpsertAccount(ctx context.Context, acc modeltiphereth.Account) error {
return a.data.db.Account.Create().
SetID(acc.ID).
SetPlatform(acc.Platform).
SetPlatformAccountID(acc.PlatformAccountID).
SetName(acc.Name).
SetProfileURL(acc.ProfileURL).
SetAvatarURL(acc.AvatarURL).
OnConflict(
sql.ConflictColumns(account.FieldPlatform, account.FieldPlatformAccountID),
resolveWithIgnores([]string{
account.FieldID,
account.FieldPlatform,
account.FieldPlatformAccountID,
}),
).
Exec(ctx)
}

Expand Down

0 comments on commit 699263b

Please sign in to comment.