diff --git a/backend/baseService/internal/applications/interface/accountserviceiface/interface.go b/backend/baseService/internal/applications/interface/accountserviceiface/interface.go index 01d127e..4fc0a57 100644 --- a/backend/baseService/internal/applications/interface/accountserviceiface/interface.go +++ b/backend/baseService/internal/applications/interface/accountserviceiface/interface.go @@ -2,6 +2,7 @@ package accountserviceiface import ( "context" + "github.com/cloudzenith/DouTok/backend/baseService/api" "github.com/cloudzenith/DouTok/backend/baseService/internal/domain/service/accountservice" ) @@ -12,6 +13,7 @@ type AccountService interface { CheckPasswordByMobile(ctx context.Context, mobile, password string) (int64, error) 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 } var _ AccountService = (*accountservice.Service)(nil) diff --git a/backend/baseService/internal/domain/repoiface/account.go b/backend/baseService/internal/domain/repoiface/account.go index 2ed37b7..6b234c8 100644 --- a/backend/baseService/internal/domain/repoiface/account.go +++ b/backend/baseService/internal/domain/repoiface/account.go @@ -3,6 +3,7 @@ package repoiface import ( "context" "github.com/cloudzenith/DouTok/backend/baseService/internal/infrastructure/dal/models" + "gorm.io/gen/field" ) //go:generate mockgen -source=account.go -destination=account_mock.go -package=repoiface AccountRepository @@ -14,4 +15,5 @@ type AccountRepository interface { GetByEmail(ctx context.Context, email string) (*models.Account, error) IsMobileExist(ctx context.Context, mobile string) (bool, error) IsEmailExist(ctx context.Context, email string) (bool, error) + ClearColumn(ctx context.Context, column field.Expr) error } diff --git a/backend/baseService/internal/domain/service/accountservice/service.go b/backend/baseService/internal/domain/service/accountservice/service.go index 52af43c..699f0bc 100644 --- a/backend/baseService/internal/domain/service/accountservice/service.go +++ b/backend/baseService/internal/domain/service/accountservice/service.go @@ -3,9 +3,13 @@ package accountservice import ( "context" "errors" + "github.com/TremblingV5/box/dbtx" + "github.com/cloudzenith/DouTok/backend/baseService/api" "github.com/cloudzenith/DouTok/backend/baseService/internal/domain/entity/account" "github.com/cloudzenith/DouTok/backend/baseService/internal/domain/repoiface" "github.com/cloudzenith/DouTok/backend/baseService/internal/infrastructure/dal/models" + "github.com/cloudzenith/DouTok/backend/baseService/internal/infrastructure/dal/query" + "gorm.io/gen/field" ) type Service struct { @@ -139,3 +143,26 @@ func (s *Service) ModifyPassword(ctx context.Context, id int64, oldPassword, new return nil } + +func (s *Service) Unbind(ctx context.Context, id int64, voucherType api.VoucherType) (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.ClearColumn(ctx, column) +} diff --git a/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go b/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go index 20a153a..27e890d 100644 --- a/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go +++ b/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go @@ -2,8 +2,10 @@ package accountrepo import ( "context" + "github.com/TremblingV5/box/dbtx" "github.com/cloudzenith/DouTok/backend/baseService/internal/infrastructure/dal/query" "gorm.io/gen" + "gorm.io/gen/field" "github.com/cloudzenith/DouTok/backend/baseService/internal/infrastructure/dal/models" ) @@ -70,3 +72,10 @@ func (r *PersistRepository) IsMobileExist(ctx context.Context, mobile string) (b func (r *PersistRepository) IsEmailExist(ctx context.Context, email string) (bool, error) { return r.isExist(ctx, query.Q.Account.Email.Eq(email)) } + +func (r *PersistRepository) ClearColumn(ctx context.Context, column field.Expr) error { + return dbtx.TxDo(ctx, func(tx *query.QueryTx) error { + _, err := tx.WithContext(ctx).Account.Update(column, nil) + return err + }) +}