feat: implemented user to post relationship creation

This commit is contained in:
SoXX 2024-02-16 17:24:39 +01:00
parent 924416dd06
commit 1919cf5c76
2 changed files with 27 additions and 2 deletions

View File

@ -36,3 +36,29 @@ func EstablishAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverW
return nil
}
func EstablishUserToPostLink(ctx context.Context, driver neo4j.DriverWithContext, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
query := `
MATCH (user:User {user_id: $anthrove_user_id})
MATCH (anthrovePost:AnthrovePost {post_id: $anthrove_post_id})
MERGE (user)-[:FAV]->(anthrovePost)
`
params := map[string]any{
"anthrove_post_id": anthrovePost.PostID,
"anthrove_user_id": anthroveUser.UserID,
}
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
if err != nil {
return err
}
log.WithFields(log.Fields{
"anthrove_post_id": anthrovePost.PostID,
"anthrove_user_id": anthroveUser.UserID,
}).Trace("graph: created user to post link")
return nil
}

View File

@ -57,8 +57,7 @@ func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID
}
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
//TODO implement me
panic("implement me")
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
}
func (g *graphConnection) VerifyUserPostLink(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveUser *models.AnthroveUser) (bool, error) {