feat: added source node creation
This commit is contained in:
parent
17631b1815
commit
5ebb855c63
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user