From 5ebb855c63da3ea9d7a167947d378eadfdc1fb37 Mon Sep 17 00:00:00 2001 From: SoXX Date: Fri, 16 Feb 2024 16:00:14 +0100 Subject: [PATCH] feat: added source node creation --- internal/source.go | 34 ++++++++++++++++++++++++++++++++++ pkg/impl.go | 3 +-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/internal/source.go b/internal/source.go index 5bf0569..619e4e5 100644 --- a/internal/source.go +++ b/internal/source.go @@ -1 +1,35 @@ package internal + +import ( + "context" + "fmt" + + "git.dragse.it/anthrove/anthrove-graph-sdk.git/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("neo4j: created source node") + + return nil +} diff --git a/pkg/impl.go b/pkg/impl.go index 8a73be8..a6ab532 100644 --- a/pkg/impl.go +++ b/pkg/impl.go @@ -41,8 +41,7 @@ func (g *graphConnection) AddUserToGraph(ctx context.Context, anthroveUserID mod } func (g *graphConnection) AddSourceToGraph(ctx context.Context, anthroveSource *models.AnthroveSource) error { - //TODO implement me - panic("implement me") + return internal.CreateSourceNode(ctx, g.driver, anthroveSource) } func (g *graphConnection) AddPostToGraph(ctx context.Context, anthrovePost *models.AnthrovePost) error {