fix: align admin behavior and Kratos integrations
This commit is contained in:
+57
-20
@@ -5,19 +5,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Dictionary struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
Type string
|
||||
Status bool
|
||||
Desc string
|
||||
ParentID *uint
|
||||
Children []*Dictionary
|
||||
Details []*DictionaryDetail
|
||||
}
|
||||
|
||||
type DictionaryDetail struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
@@ -34,16 +21,66 @@ type DictionaryDetail struct {
|
||||
Children []*DictionaryDetail
|
||||
}
|
||||
|
||||
type DictionaryRepo interface {
|
||||
CreateDictionary(context.Context, *Dictionary) error
|
||||
UpdateDictionary(context.Context, *Dictionary) error
|
||||
DeleteDictionary(context.Context, uint) error
|
||||
FindDictionary(context.Context, uint, string, bool) (*Dictionary, error)
|
||||
ListDictionaries(context.Context, int, int, string, string, bool) ([]*Dictionary, int64, error)
|
||||
type DictionaryDetailFilter struct {
|
||||
DictionaryID uint
|
||||
Label string
|
||||
Value string
|
||||
Status *bool
|
||||
ParentID *uint
|
||||
Level *int
|
||||
}
|
||||
|
||||
type DictionaryDetailRepo interface {
|
||||
CreateDictionaryDetail(context.Context, *DictionaryDetail) error
|
||||
UpdateDictionaryDetail(context.Context, *DictionaryDetail) error
|
||||
DeleteDictionaryDetail(context.Context, uint) error
|
||||
FindDictionaryDetail(context.Context, uint) (*DictionaryDetail, error)
|
||||
ListDictionaryDetails(context.Context, int, int, uint, string, string) ([]*DictionaryDetail, int64, error)
|
||||
ListDictionaryDetails(context.Context, int, int, DictionaryDetailFilter) ([]*DictionaryDetail, int64, error)
|
||||
DictionaryDetailTree(context.Context, uint, string) ([]*DictionaryDetail, error)
|
||||
}
|
||||
|
||||
type Dictionary struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
Type string
|
||||
Status bool
|
||||
Desc string
|
||||
ParentID *uint
|
||||
Children []*Dictionary
|
||||
Details []*DictionaryDetail
|
||||
}
|
||||
|
||||
type DictionaryRepo interface {
|
||||
DictionaryMetadataRepo
|
||||
DictionaryDetailRepo
|
||||
}
|
||||
|
||||
type DictionaryMetadataRepo interface {
|
||||
CreateDictionary(context.Context, *Dictionary) error
|
||||
ImportDictionary(context.Context, *Dictionary, []*DictionaryDetail) error
|
||||
UpdateDictionary(context.Context, *Dictionary) error
|
||||
DeleteDictionary(context.Context, uint) error
|
||||
FindDictionary(context.Context, uint, string, *bool, bool) (*Dictionary, error)
|
||||
ExportDictionary(context.Context, uint) (*Dictionary, error)
|
||||
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 *SettingsUsecase) DictionaryDetailsByParent(ctx context.Context, dictionaryID, parentID uint) ([]*DictionaryDetail, error) {
|
||||
items, _, err := uc.ListDictionaryDetails(ctx, 0, 0, DictionaryDetailFilter{DictionaryID: dictionaryID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*DictionaryDetail, 0)
|
||||
for _, item := range items {
|
||||
if (parentID == 0 && item.ParentID == nil) || (item.ParentID != nil && *item.ParentID == parentID) {
|
||||
out = append(out, item)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user