This repository has been archived on 2025-05-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
synchronizator-go/pkg/platform.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
}