feat: add platform-collection relationship in platform.FetchCollection()

This commit is contained in:
Alexander Navarro 2024-11-25 19:54:41 -03:00
parent 8af94161ab
commit c1684c8dea
7 changed files with 184 additions and 79 deletions

View file

@ -10,9 +10,13 @@ type default_collection struct {
platform_name string
}
func (collection *default_collection) ToNode() (string, []byte, error) {
func (collection *default_collection) GetClass() string {
platform_name := strings.ToUpper(collection.platform_name)
return platform_name + "_DEFAULT", nil, nil
return platform_name + "_DEFAULT"
}
func (collection *default_collection) GetMetadata() []byte {
return nil
}
func (collection *default_collection) FromNode(_class string, name string, metadata []byte) error {
@ -46,13 +50,19 @@ func NewCollection(name string, metadata []byte) *Collection {
}
// Internal RelationshipClass to handle the collection to node relationship
type collection_relation struct{}
func (collection *collection_relation) ToRelationship() (string, []byte, error) {
return "COLLECTION_HAS", nil, nil
type collection_has_node struct {
Relationship
}
func (collection *collection_relation) FromRelationship(_class string, metadata []byte) error {
func (col_has_node *collection_has_node) GetClass() string {
return "COLLECTION_HAS"
}
func (col_has_node *collection_has_node) GetMetadata() []byte {
return nil
}
func (col_has_node *collection_has_node) FromRelationship(_class string, metadata []byte) error {
if _class != "COLLECTION_HAS" {
return fmt.Errorf("invalid class %s", _class)
}
@ -62,7 +72,7 @@ func (collection *collection_relation) FromRelationship(_class string, metadata
// Adds a new child to this collection. Use the underlaying node's AddRelation
// method.
func (collection *Collection) AddChild(node *Node) error {
_, err := collection.AddRelation(&collection_relation{}, node.Id)
_, err := collection.StoreRelation(&collection_has_node{}, node.Id)
if err != nil {
return err
}