Skip to content

Commit 699263b

Browse files
committed
fix(tiphereth): sync pull account on linking
1 parent ca5b399 commit 699263b

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

app/sephirah/internal/biz/bizangela/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewPullAccountTopic(
3434
if err != nil {
3535
return err
3636
}
37-
err = a.repo.UpdateAccount(ctx, modeltiphereth.Account{
37+
err = a.repo.UpsertAccount(ctx, modeltiphereth.Account{
3838
ID: info.ID,
3939
Platform: info.Platform,
4040
PlatformAccountID: info.PlatformAccountID,

app/sephirah/internal/biz/bizangela/angela.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type AngelaBase struct {
4848
}
4949

5050
type AngelaRepo interface {
51-
UpdateAccount(context.Context, modeltiphereth.Account) error
51+
UpsertAccount(context.Context, modeltiphereth.Account) error
5252
UpsertAppInfo(context.Context, *modelgebura.AppInfo, *modelgebura.AppInfo) error
5353
UpsertAppInfos(context.Context, []*modelgebura.AppInfo) error
5454
AccountPurchaseAppInfos(context.Context, model.InternalID, []model.InternalID) error

app/sephirah/internal/biz/biztiphereth/account.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ func (t *Tiphereth) LinkAccount(
2929
return nil, pb.ErrorErrorReasonUnspecified("%s", err)
3030
}
3131
a.ID = id
32-
a.ID, err = t.repo.LinkAccount(ctx, a, claims.UserID)
33-
if err != nil {
34-
return nil, pb.ErrorErrorReasonUnspecified("%s", err.Error())
35-
}
36-
if err = t.pullAccount.Publish(ctx, modeltiphereth.PullAccountInfo{
32+
if err = t.pullAccount.LocalCall(ctx, modeltiphereth.PullAccountInfo{
3733
ID: a.ID,
3834
Platform: a.Platform,
3935
PlatformAccountID: a.PlatformAccountID,
4036
}); err != nil {
41-
logger.Errorf("Publish PullAccountInfo failed %s", err.Error())
37+
logger.Errorf("PullAccountInfo failed %s", err.Error())
38+
return nil, pb.ErrorErrorReasonUnspecified("Get Account Info failed, %s", err.Error())
39+
}
40+
a.ID, err = t.repo.LinkAccount(ctx, a, claims.UserID)
41+
if err != nil {
42+
return nil, pb.ErrorErrorReasonUnspecified("%s", err.Error())
4243
}
4344
return &a, nil
4445
}

app/sephirah/internal/data/angela.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,22 @@ func NewAngelaRepo(data *Data) bizangela.AngelaRepo {
3232
}
3333
}
3434

35-
func (a *angelaRepo) UpdateAccount(ctx context.Context, acc modeltiphereth.Account) error {
36-
return a.data.db.Account.Update().Where(
37-
account.IDEQ(acc.ID),
38-
account.PlatformEQ(acc.Platform),
39-
account.PlatformAccountIDEQ(acc.PlatformAccountID),
40-
).
35+
func (a *angelaRepo) UpsertAccount(ctx context.Context, acc modeltiphereth.Account) error {
36+
return a.data.db.Account.Create().
37+
SetID(acc.ID).
38+
SetPlatform(acc.Platform).
39+
SetPlatformAccountID(acc.PlatformAccountID).
4140
SetName(acc.Name).
4241
SetProfileURL(acc.ProfileURL).
4342
SetAvatarURL(acc.AvatarURL).
43+
OnConflict(
44+
sql.ConflictColumns(account.FieldPlatform, account.FieldPlatformAccountID),
45+
resolveWithIgnores([]string{
46+
account.FieldID,
47+
account.FieldPlatform,
48+
account.FieldPlatformAccountID,
49+
}),
50+
).
4451
Exec(ctx)
4552
}
4653

0 commit comments

Comments
 (0)