From 1919cf5c76aa5f2052519b0fbb449aee7bac11e3 Mon Sep 17 00:00:00 2001 From: SoXX Date: Fri, 16 Feb 2024 17:24:39 +0100 Subject: [PATCH] feat: implemented user to post relationship creation --- internal/relationships.go | 26 ++++++++++++++++++++++++++ pkg/impl.go | 3 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/relationships.go b/internal/relationships.go index e587587..14f1b8d 100644 --- a/internal/relationships.go +++ b/internal/relationships.go @@ -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 +} diff --git a/pkg/impl.go b/pkg/impl.go index 9afe702..66c9827 100644 --- a/pkg/impl.go +++ b/pkg/impl.go @@ -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) {