36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthroveSource *models.AnthroveSource) error {
|
|
query := `
|
|
MERGE (sourceNode:Source {domain: $source_url})
|
|
ON CREATE SET sourceNode.domain = $source_url, sourceNode.display_name = $source_display_name, sourceNode.icon = $source_icon
|
|
`
|
|
params := map[string]any{
|
|
"source_url": anthroveSource.Domain,
|
|
"source_display_name": anthroveSource.DisplayName,
|
|
"source_icon": anthroveSource.Icon,
|
|
}
|
|
|
|
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
if err != nil {
|
|
return fmt.Errorf("graph: %w", err)
|
|
}
|
|
|
|
log.WithFields(log.Fields{
|
|
"node_source_url": anthroveSource.Domain,
|
|
"node_source_displayName": anthroveSource.DisplayName,
|
|
"node_source_icon": anthroveSource.Icon,
|
|
}).Trace("graph: created source node")
|
|
|
|
return nil
|
|
}
|