From 19a92ee08331095a26e8cbe2e583786b092cac60 Mon Sep 17 00:00:00 2001 From: TremblingV5 Date: Fri, 7 Feb 2025 21:20:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(account):=20=E6=B7=BB=E5=8A=A0=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E8=A7=A3=E7=BB=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 AccountRepository 接口中添加 ClearColumn 方法 - 在 AccountService 接口中添加 Unbind 方法 - 实现 PersistRepository 中的 ClearColumn 方法 - 实现 Service 中的 Unbind 方法 -支持邮箱和手机号的解绑操作 --- .../accountserviceiface/interface.go | 2 ++ .../internal/domain/repoiface/account.go | 2 ++ .../domain/service/accountservice/service.go | 27 +++++++++++++++++++ .../repositories/accountrepo/repository.go | 9 +++++++ 4 files changed, 40 insertions(+) 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 + }) +}