优化
This commit is contained in:
@@ -389,9 +389,11 @@ func (r *dictionaryRepo) ListDictionaryDetails(ctx context.Context, page, size i
|
||||
}
|
||||
func (r *dictionaryRepo) DictionaryDetailTree(ctx context.Context, dictionaryID uint, typ string) ([]*biz.DictionaryDetail, error) {
|
||||
if dictionaryID == 0 {
|
||||
active := true
|
||||
dictionary, err := r.FindDictionary(ctx, 0, typ, &active, false)
|
||||
if err != nil {
|
||||
// The tree-by-type endpoint resolves only by dictionary type. Unlike the
|
||||
// public dictionary lookup, it does not require the dictionary itself to
|
||||
// be enabled.
|
||||
var dictionary dictionaryPO
|
||||
if err := r.data.gormDB.WithContext(ctx).Where("type = ?", typ).First(&dictionary).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dictionaryID = dictionary.ID
|
||||
@@ -409,7 +411,7 @@ func (r *dictionaryRepo) DictionaryDetailTree(ctx context.Context, dictionaryID
|
||||
for _, item := range items {
|
||||
if item.ParentID != nil && byID[*item.ParentID] != nil {
|
||||
byID[*item.ParentID].Children = append(byID[*item.ParentID].Children, item)
|
||||
} else {
|
||||
} else if item.ParentID == nil {
|
||||
roots = append(roots, item)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user