Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type AccountService interface {
CheckPasswordByEmail(ctx context.Context, email, password string) (int64, error)
ModifyPassword(ctx context.Context, id int64, oldPassword, newPassword string) error
Unbind(ctx context.Context, id int64, voucherType api.VoucherType) error
Bind(ctx context.Context, id int64, voucherType api.VoucherType, voucher string) error
}

var _ AccountService = (*accountservice.Service)(nil)
1 change: 1 addition & 0 deletions backend/baseService/internal/domain/repoiface/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type AccountRepository interface {
IsMobileExist(ctx context.Context, mobile string) (bool, error)
IsEmailExist(ctx context.Context, email string) (bool, error)
ClearColumn(ctx context.Context, column field.Expr) error
UpdateColumn(ctx context.Context, column field.Expr, value interface{}) error
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,26 @@ func (s *Service) Unbind(ctx context.Context, id int64, voucherType api.VoucherT

return s.account.ClearColumn(ctx, column)
}

func (s *Service) Bind(ctx context.Context, id int64, voucherType api.VoucherType, voucher string) (err error) {
ctx, persist := dbtx.WithTXPersist(ctx)
defer func() {
persist(err)
}()

if id == 0 {
return errors.New("账户id不能为空")
}

var column field.Expr
switch voucherType {
case api.VoucherType_VOUCHER_EMAIL:
column = query.Q.Account.Email
case api.VoucherType_VOUCHER_PHONE:
column = query.Q.Account.Mobile
default:
return errors.New("不支持的类型")
}

return s.account.UpdateColumn(ctx, column, voucher)
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,10 @@ func (r *PersistRepository) ClearColumn(ctx context.Context, column field.Expr)
return err
})
}

func (r *PersistRepository) UpdateColumn(ctx context.Context, column field.Expr, voucher interface{}) error {
return dbtx.TxDo(ctx, func(tx *query.QueryTx) error {
_, err := tx.WithContext(ctx).Account.Update(column, voucher)
return err
})
}
Loading