generated from alecodes/base-template
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package synchronizator
|
|
|
|
import "slices"
|
|
|
|
// Utility struct to represent a collection of nodes, it's a [Node] itself so all
|
|
// the node's functionality is available.
|
|
type Platform struct {
|
|
Node // Underlaying node info
|
|
Collections []*Collection // Child nodes
|
|
}
|
|
|
|
func (platform *Platform) FetchCollections(fetcher Fetcher, start_pagination Pagination) error {
|
|
collections, pagination, err := fetcher(start_pagination)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
platform.Collections = slices.Concat(platform.Collections, collections)
|
|
|
|
if pagination.HasMore {
|
|
return platform.FetchCollections(fetcher, pagination)
|
|
}
|
|
|
|
err = BulkCreateNode(platform._conn, platform.Collections)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, item := range platform.Collections {
|
|
err := platform.AddRelationship(
|
|
&Relationship{
|
|
_class: "PLATFORM_HAS_COLLECTION",
|
|
From: platform.Id,
|
|
To: item.Id,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
err = BulkCreateRelationships(platform._conn, platform._relationships)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|