f
This commit is contained in:
31
internal/infrastructure/subordinate/account_kind_provider.go
Normal file
31
internal/infrastructure/subordinate/account_kind_provider.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package subordinate
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyapi-server/internal/domains/subordinate/repositories"
|
||||
"tyapi-server/internal/shared/auth"
|
||||
"tyapi-server/internal/shared/interfaces"
|
||||
)
|
||||
|
||||
// AccountKindProviderImpl 从主从表判断 account_kind
|
||||
type AccountKindProviderImpl struct {
|
||||
repo repositories.SubordinateRepository
|
||||
}
|
||||
|
||||
// NewAccountKindProviderImpl 构造
|
||||
func NewAccountKindProviderImpl(repo repositories.SubordinateRepository) interfaces.AccountKindProvider {
|
||||
return &AccountKindProviderImpl{repo: repo}
|
||||
}
|
||||
|
||||
// AccountKind 返回 standalone 或 subordinate
|
||||
func (p *AccountKindProviderImpl) AccountKind(ctx context.Context, userID string) (string, error) {
|
||||
ok, err := p.repo.IsUserSubordinate(ctx, userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if ok {
|
||||
return auth.AccountKindSubordinate, nil
|
||||
}
|
||||
return auth.AccountKindStandalone, nil
|
||||
}
|
||||
Reference in New Issue
Block a user