feat: implemented tag creation & renamed function to be more clear what they actually do
This commit is contained in:
parent
82d87f388c
commit
d9f25a5a87
@ -1 +1,35 @@
|
|||||||
package internal
|
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
|
||||||
|
}
|
||||||
|
16
pkg/graph.go
16
pkg/graph.go
@ -10,17 +10,17 @@ type Graph interface {
|
|||||||
// Connect sets up a connection to the endpoint using the provided username and password
|
// 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
|
Connect(ctx context.Context, endpoint string, username string, password string) error
|
||||||
|
|
||||||
// AddUserToGraph uploads an Anthrove user to the graph
|
// AddUserWithRelationToSource uploads an Anthrove user to the graph
|
||||||
AddUserToGraph(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, error)
|
AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, error)
|
||||||
|
|
||||||
// AddSourceToGraph uploads an Anthrove source to the graph
|
// AddSource uploads an Anthrove source to the graph
|
||||||
AddSourceToGraph(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
||||||
|
|
||||||
// AddPostToGraph uploads an Anthrove post to the graph
|
// AddPost uploads an Anthrove post to the graph
|
||||||
AddPostToGraph(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
||||||
|
|
||||||
// AddTagToGraph uploads a tag associated with an Anthrove post to the graph
|
// AddTagWithRelationToPost uploads a tag associated with an Anthrove post to the graph
|
||||||
AddTagToGraph(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveTag *models.AnthroveTag) error
|
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 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
|
LinkPostWithSource(ctx context.Context, anthrovePost *models.AnthrovePost, anthrovePostRelationship *models.AnthrovePostRelationship, anthroveSource *models.AnthroveSource) error
|
||||||
|
11
pkg/impl.go
11
pkg/impl.go
@ -36,21 +36,20 @@ func (g *graphConnection) Connect(ctx context.Context, endpoint string, username
|
|||||||
return nil
|
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)
|
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)
|
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)
|
return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) AddTagToGraph(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveTag *models.AnthroveTag) error {
|
func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID *models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
|
||||||
//TODO implement me
|
return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePost *models.AnthrovePost, anthrovePostRelationship *models.AnthrovePostRelationship, anthroveSource *models.AnthroveSource) error {
|
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePost *models.AnthrovePost, anthrovePostRelationship *models.AnthrovePostRelationship, anthroveSource *models.AnthroveSource) error {
|
||||||
|
Reference in New Issue
Block a user