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 @@ -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"
)

Expand All @@ -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)
2 changes: 2 additions & 0 deletions backend/baseService/internal/domain/repoiface/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
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 {
Expand Down Expand Up @@ -139,3 +143,26 @@

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)
}()

Check warning on line 151 in backend/baseService/internal/domain/service/accountservice/service.go

View check run for this annotation

Codecov / codecov/patch

backend/baseService/internal/domain/service/accountservice/service.go#L147-L151

Added lines #L147 - L151 were not covered by tests

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

Check warning on line 155 in backend/baseService/internal/domain/service/accountservice/service.go

View check run for this annotation

Codecov / codecov/patch

backend/baseService/internal/domain/service/accountservice/service.go#L153-L155

Added lines #L153 - L155 were not covered by tests

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("不支持的类型")

Check warning on line 164 in backend/baseService/internal/domain/service/accountservice/service.go

View check run for this annotation

Codecov / codecov/patch

backend/baseService/internal/domain/service/accountservice/service.go#L157-L164

Added lines #L157 - L164 were not covered by tests
}

return s.account.ClearColumn(ctx, column)

Check warning on line 167 in backend/baseService/internal/domain/service/accountservice/service.go

View check run for this annotation

Codecov / codecov/patch

backend/baseService/internal/domain/service/accountservice/service.go#L167

Added line #L167 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

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"
)
Expand Down Expand Up @@ -70,3 +72,10 @@
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
})

Check warning on line 80 in backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go

View check run for this annotation

Codecov / codecov/patch

backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go#L76-L80

Added lines #L76 - L80 were not covered by tests
}
Loading