feat: 迁移商务旗下渠道查询和抽屉

This commit is contained in:
Yvan
2026-11-03 19:20:42 +08:00
parent 8048dfb514
commit cd42a1d3f0
29 changed files with 409 additions and 20 deletions
+1 -1
View File
@@ -11,4 +11,4 @@ import (
)
// ProviderSet is biz providers.
var ProviderSet = wire.NewSet(system.ProviderSet, payment.ProviderSet, integration.ProviderSet, task.ProviderSet, business.NewUserPreferenceUsecase, business.NewAccountUsecase, business.NewBindingUsecase, business.NewPasswordResetUsecase)
var ProviderSet = wire.NewSet(system.ProviderSet, payment.ProviderSet, integration.ProviderSet, task.ProviderSet, business.NewUserPreferenceUsecase, business.NewAccountUsecase, business.NewBindingUsecase, business.NewPasswordResetUsecase, business.NewBusinessPromoteUsecase)
+36
View File
@@ -0,0 +1,36 @@
package business
import "context"
type BusinessPromote struct {
ID uint64
Account, SourceDB string
BusierID uint64
}
type BusinessPromoteFilter struct {
UserID uint
SourceDB string
BusierID uint64
}
type BusinessPromotePage struct {
Rows []*BusinessPromote
Total int64
Available bool
}
type BusinessPromoteRepo interface {
ListDirect(context.Context, BusinessPromoteFilter, ...ListOption) (*BusinessPromotePage, error)
}
type BusinessPromoteUsecase struct {
repo BusinessPromoteRepo
accounts *AccountUsecase
}
func NewBusinessPromoteUsecase(repo BusinessPromoteRepo, accounts *AccountUsecase) *BusinessPromoteUsecase {
return &BusinessPromoteUsecase{repo: repo, accounts: accounts}
}
func (uc *BusinessPromoteUsecase) List(ctx context.Context, filter BusinessPromoteFilter, options ...ListOption) (*BusinessPromotePage, error) {
if _, err := uc.accounts.Find(ctx, filter.UserID); err != nil {
return nil, err
}
return uc.repo.ListDirect(ctx, filter, options...)
}
@@ -0,0 +1,24 @@
package business
import (
"context"
"testing"
)
type directPromoteRepoFake struct{ calls int }
func (r *directPromoteRepoFake) ListDirect(context.Context, BusinessPromoteFilter, ...ListOption) (*BusinessPromotePage, error) {
r.calls++
return &BusinessPromotePage{Available: true}, nil
}
func TestDirectPromotesCheckUserScopeBeforeReadingChannels(t *testing.T) {
a := &accountRepoFake{accounts: map[uint]*Account{12: {ID: 12, Level: 1, IDPath: "0"}, 13: {ID: 13, Level: 2, IDPath: "0,12"}, 99: {ID: 99, Level: 2, IDPath: "0,123"}}}
r := &directPromoteRepoFake{}
uc := NewBusinessPromoteUsecase(r, NewAccountUsecase(a))
if _, err := uc.List(accountContext(12, 901), BusinessPromoteFilter{UserID: 99}); err != ErrAccountScope || r.calls != 0 {
t.Fatal("越权请求触达了渠道仓储")
}
if _, err := uc.List(accountContext(12, 901), BusinessPromoteFilter{UserID: 13}); err != nil || r.calls != 1 {
t.Fatal("下级渠道查询未执行")
}
}