feat: implemented tag creation & renamed function to be more clear what they actually do

This commit is contained in:
SoXX 2024-02-16 16:16:57 +01:00
parent 82d87f388c
commit d9f25a5a87
3 changed files with 47 additions and 14 deletions

View File

@ -1 +1,35 @@
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 CreateTagNodeWitRelation(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID *models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
query := `
MATCH (anthrovePost:AnthrovePost {post_id: $anthrove_post_id})
MERGE (tagNode:Tag {name: $tag_name, type: $tag_type})
MERGE (anthrovePost)-[:HAS]->(tagNode)
`
params := map[string]interface{}{
"tag_name": anthroveTag.Name,
"tag_type": anthroveTag.Type,
"anthrove_post_id": anthrovePostID,
}
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
if err != nil {
return err
}
log.WithFields(log.Fields{
"anthrove_post_id": anthrovePostID,
"tag_name": anthroveTag.Name,
"tag_type": anthroveTag.Type,
}).Trace("graph: created tag node")
return nil
}

View File

@ -10,17 +10,17 @@ type Graph interface {
// Connect sets up a connection to the endpoint using the provided username and password
Connect(ctx context.Context, endpoint string, username string, password string) error
// AddUserToGraph uploads an Anthrove user to the graph
AddUserToGraph(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, error)
// AddUserWithRelationToSource uploads an Anthrove user to the graph
AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, error)
// AddSourceToGraph uploads an Anthrove source to the graph
AddSourceToGraph(ctx context.Context, anthroveSource *models.AnthroveSource) error
// AddSource uploads an Anthrove source to the graph
AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
// AddPostToGraph uploads an Anthrove post to the graph
AddPostToGraph(ctx context.Context, anthrovePost *models.AnthrovePost) error
// AddPost uploads an Anthrove post to the graph
AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error
// AddTagToGraph uploads a tag associated with an Anthrove post to the graph
AddTagToGraph(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveTag *models.AnthroveTag) error
// AddTagWithRelationToPost uploads a tag associated with an Anthrove post to the graph
AddTagWithRelationToPost(ctx context.Context, anthrovePostID *models.AnthrovePostID, anthroveTag *models.AnthroveTag) error
// LinkPostWithSource establishes a link between a post and a source in the graph
LinkPostWithSource(ctx context.Context, anthrovePost *models.AnthrovePost, anthrovePostRelationship *models.AnthrovePostRelationship, anthroveSource *models.AnthroveSource) error

View File

@ -36,21 +36,20 @@ func (g *graphConnection) Connect(ctx context.Context, endpoint string, username
return nil
}
func (g *graphConnection) AddUserToGraph(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, error) {
func (g *graphConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, error) {
return internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
}
func (g *graphConnection) AddSourceToGraph(ctx context.Context, anthroveSource *models.AnthroveSource) error {
func (g *graphConnection) AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
return internal.CreateSourceNode(ctx, g.driver, anthroveSource)
}
func (g *graphConnection) AddPostToGraph(ctx context.Context, anthrovePost *models.AnthrovePost) error {
func (g *graphConnection) AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
}
func (g *graphConnection) AddTagToGraph(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveTag *models.AnthroveTag) error {
//TODO implement me
panic("implement me")
func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID *models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
}
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePost *models.AnthrovePost, anthrovePostRelationship *models.AnthrovePostRelationship, anthroveSource *models.AnthroveSource) error {