flamingo.me/flamingo-commerce/v3@v3.11.0/category/domain/tree.go (about)

     1  package domain
     2  
     3  type (
     4  
     5  	// Tree domain model
     6  	Tree interface {
     7  		//Code - returns the idendifier of the category
     8  		Code() string
     9  		//Name - returns the name of the category
    10  		Name() string
    11  		//Path returns the Path as string
    12  		Path() string
    13  		//Active - should return true if the category is in the rootpath of the current category
    14  		Active() bool
    15  		//Subtrees returns a list of subtrees of the current node
    16  		SubTrees() []Tree
    17  		//HasChilds returns true if the node is no leaf node
    18  		HasChilds() bool
    19  		//DocumentCount - the amount of documents (products) in the category
    20  		DocumentCount() int
    21  	}
    22  
    23  	// TreeData defines the default domain tree data model
    24  	TreeData struct {
    25  		CategoryCode          string
    26  		CategoryName          string
    27  		CategoryPath          string
    28  		CategoryDocumentCount int
    29  		SubTreesData          []*TreeData
    30  		IsActive              bool
    31  	}
    32  )
    33  
    34  // Active gets the node (category) active state
    35  func (c TreeData) Active() bool {
    36  	return c.IsActive
    37  }
    38  
    39  // Code gets the category code represented by this node in the tree
    40  func (c TreeData) Code() string {
    41  	return c.CategoryCode
    42  }
    43  
    44  // Name gets the category name
    45  func (c TreeData) Name() string {
    46  	return c.CategoryName
    47  }
    48  
    49  // Path gets the Node (category) path
    50  func (c TreeData) Path() string {
    51  	return c.CategoryPath
    52  }
    53  
    54  // DocumentCount gets the amount of documents in that node
    55  func (c TreeData) DocumentCount() int {
    56  	return c.CategoryDocumentCount
    57  }
    58  
    59  // SubTrees gets the child Trees
    60  func (c TreeData) SubTrees() []Tree {
    61  	result := make([]Tree, len(c.SubTreesData))
    62  	for i, child := range c.SubTreesData {
    63  		result[i] = Tree(child)
    64  	}
    65  
    66  	return result
    67  }
    68  
    69  // HasChilds - true if subTrees exist
    70  func (c TreeData) HasChilds() bool {
    71  	return len(c.SubTreesData) > 0
    72  }