diff --git a/internal/source/source.go b/internal/source/source.go index 8ae40c5..48e992d 100644 --- a/internal/source/source.go +++ b/internal/source/source.go @@ -35,6 +35,30 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr return nil } +// DeleteSourceNode will delete a node with a given Domain +func DeleteSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthroveSource *models.AnthroveSource) error { + query := ` + MERGE (sourceNode:Source {domain: $domain}) + DELETE sourceNode + ` + params := map[string]any{ + "domain": anthroveSource.Domain, + } + + _, 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 +} + func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]models.AnthroveSource, error) { var sources []models.AnthroveSource diff --git a/pkg/graph/source.go b/pkg/graph/source.go index 903a439..08f150f 100644 --- a/pkg/graph/source.go +++ b/pkg/graph/source.go @@ -10,6 +10,8 @@ type Source interface { // CreateSource will always create a new node, it checks if a node with the same url exits and merges it. CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error + + // DeleteSource will delete a node with a given Domain DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error // GetSourceByURL returns the Source Node based on the URL diff --git a/pkg/graph/source_impl.go b/pkg/graph/source_impl.go index ca9e4bc..56d2b1b 100644 --- a/pkg/graph/source_impl.go +++ b/pkg/graph/source_impl.go @@ -13,9 +13,9 @@ func (g *graphConnection) CreateSource(ctx context.Context, anthroveSource *mode return source.CreateSourceNode(ctx, g.driver, anthroveSource) } +// DeleteSource will delete a node with a given Domain func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error { - //TODO implement me - panic("implement me") + return source.DeleteSourceNode(ctx, g.driver, anthroveSource) } func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {