diff --git a/internal/post.go b/internal/post.go index 5bf0569..254cd78 100644 --- a/internal/post.go +++ b/internal/post.go @@ -1 +1,32 @@ package internal + +import ( + "context" + + "git.dragse.it/anthrove/anthrove-graph-sdk.git/pkg/models" + "github.com/neo4j/neo4j-go-driver/v5/neo4j" + log "github.com/sirupsen/logrus" +) + +func CreateAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) error { + query := ` + CREATE (newPostNode:AnthrovePost {post_id: $anthrove_post_id, rating: $anthrove_rating}) + ` + + params := map[string]any{ + "anthrove_post_id": anthrovePost.PostID, + "anthrove_rating": anthrovePost.Rating, + } + + _, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer) + if err != nil { + return err + } + + log.WithFields(log.Fields{ + "anthrove_post_id": anthrovePost.PostID, + "anthrove_post_rating": anthrovePost.Rating, + }).Trace("graph: created anthrove post") + + return nil +} diff --git a/pkg/impl.go b/pkg/impl.go index a6ab532..8d2e8e2 100644 --- a/pkg/impl.go +++ b/pkg/impl.go @@ -45,8 +45,7 @@ func (g *graphConnection) AddSourceToGraph(ctx context.Context, anthroveSource * } func (g *graphConnection) AddPostToGraph(ctx context.Context, anthrovePost *models.AnthrovePost) error { - //TODO implement me - panic("implement me") + return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost) } func (g *graphConnection) AddTagToGraph(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveTag *models.AnthroveTag) error {