This commit is contained in:
2026-08-15 01:40:51 +08:00
parent 2f165d3a45
commit e55fb57432
29 changed files with 163 additions and 124 deletions
+9 -3
View File
@@ -29,7 +29,13 @@ type APITokenRepo interface {
IsTokenDisabled(context.Context, string) (bool, error)
}
func (uc *SettingsUsecase) PrepareAPIToken(ctx context.Context, userID, authorityID uint, days int) (*User, time.Duration, error) {
type TokenUsecase struct{ APITokenRepo }
func NewTokenUsecase(repo APITokenRepo) *TokenUsecase {
return &TokenUsecase{APITokenRepo: repo}
}
func (uc *TokenUsecase) PrepareAPIToken(ctx context.Context, userID, authorityID uint, days int) (*User, time.Duration, error) {
user, allowed, err := uc.UserHasAuthority(ctx, userID, authorityID)
if err != nil {
return nil, 0, err
@@ -44,6 +50,6 @@ func (uc *SettingsUsecase) PrepareAPIToken(ctx context.Context, userID, authorit
return user, duration, nil
}
func (uc *SettingsUsecase) DisableToken(ctx context.Context, id uint) error {
return uc.SettingsRepo.DisableAndBlacklistAPIToken(ctx, id)
func (uc *TokenUsecase) DisableToken(ctx context.Context, id uint) error {
return uc.APITokenRepo.DisableAndBlacklistAPIToken(ctx, id)
}
+1 -1
View File
@@ -3,4 +3,4 @@ package biz
import "github.com/google/wire"
// ProviderSet is biz providers.
var ProviderSet = wire.NewSet(NewUserUsecase, NewSystemConfigUsecase, NewAccessUsecase, NewMenuUsecase, NewOrganizationUsecase, NewSettingsUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewTaskUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase)
var ProviderSet = wire.NewSet(NewUserUsecase, NewSystemConfigUsecase, NewAccessUsecase, NewMenuUsecase, NewOrganizationUsecase, NewDictionaryUsecase, NewParameterUsecase, NewTokenUsecase, NewSecurityUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewTaskUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase)
+9 -3
View File
@@ -57,6 +57,12 @@ type DictionaryRepo interface {
DictionaryDetailRepo
}
type DictionaryUsecase struct{ DictionaryRepo }
func NewDictionaryUsecase(repo DictionaryRepo) *DictionaryUsecase {
return &DictionaryUsecase{DictionaryRepo: repo}
}
type DictionaryMetadataRepo interface {
CreateDictionary(context.Context, *Dictionary) error
ImportDictionary(context.Context, *Dictionary, []*DictionaryDetail) error
@@ -67,11 +73,11 @@ type DictionaryMetadataRepo interface {
ListDictionaries(context.Context, int, int, string, string, bool) ([]*Dictionary, int64, error)
}
func (uc *SettingsUsecase) ImportDictionary(ctx context.Context, dictionary *Dictionary, details []*DictionaryDetail) error {
return uc.SettingsRepo.ImportDictionary(ctx, dictionary, details)
func (uc *DictionaryUsecase) ImportDictionary(ctx context.Context, dictionary *Dictionary, details []*DictionaryDetail) error {
return uc.DictionaryRepo.ImportDictionary(ctx, dictionary, details)
}
func (uc *SettingsUsecase) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*DictionaryDetail, error) {
func (uc *DictionaryUsecase) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*DictionaryDetail, error) {
items, _, err := uc.ListDictionaryDetails(ctx, 0, 0, DictionaryDetailFilter{DictionaryID: dictionaryID})
if err != nil {
return nil, err
+6
View File
@@ -24,3 +24,9 @@ type ParameterRepo interface {
FindParameter(context.Context, uint, string) (*SystemParameter, error)
ListParameters(context.Context, int, int, *SystemParameter) ([]*SystemParameter, int64, error)
}
type ParameterUsecase struct{ ParameterRepo }
func NewParameterUsecase(repo ParameterRepo) *ParameterUsecase {
return &ParameterUsecase{ParameterRepo: repo}
}
+8 -2
View File
@@ -33,11 +33,17 @@ type SecurityRepo interface {
SaveSecurityConfig(context.Context, *SecurityConfig) error
}
func (uc *SettingsUsecase) UpdateSecurity(ctx context.Context, value *SecurityConfig) error {
type SecurityUsecase struct{ SecurityRepo }
func NewSecurityUsecase(repo SecurityRepo) *SecurityUsecase {
return &SecurityUsecase{SecurityRepo: repo}
}
func (uc *SecurityUsecase) UpdateSecurity(ctx context.Context, value *SecurityConfig) error {
return uc.SaveSecurityConfig(ctx, value)
}
func (uc *SettingsUsecase) ValidatePassword(value *SecurityConfig, password string) error {
func (uc *SecurityUsecase) ValidatePassword(value *SecurityConfig, password string) error {
if len([]rune(password)) < value.PwdMinLength {
return errors.New("密码长度不足")
}
-14
View File
@@ -1,14 +0,0 @@
package biz
type SettingsRepo interface {
DictionaryRepo
ParameterRepo
APITokenRepo
SecurityRepo
}
type SettingsUsecase struct{ SettingsRepo }
func NewSettingsUsecase(repo SettingsRepo) *SettingsUsecase {
return &SettingsUsecase{SettingsRepo: repo}
}