32 lines
847 B
Go
32 lines
847 B
Go
|
|
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
|
||
|
|
}
|