From 5446f49a3555405a9ca31dca208a7754c95677c6 Mon Sep 17 00:00:00 2001 From: SoXX Date: Fri, 31 May 2024 15:03:38 +0200 Subject: [PATCH] refactor(post): renamed functions & added documentation Signed-off-by: SoXX --- internal/post.go | 9 ++++++--- pkg/graph/post_impl.go | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/internal/post.go b/internal/post.go index ac3e248..5cb765d 100644 --- a/internal/post.go +++ b/internal/post.go @@ -55,7 +55,8 @@ func DeleteAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext, return nil } -func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) { +// AnthroveNodeExistsByAnthroveID checks if a models.AnthrovePost exists by its models.AnthrovePostID. +func AnthroveNodeExistsByAnthroveID(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) { query := ` OPTIONAL MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id}) RETURN postNode.post_id AS AnthrovePostID @@ -73,7 +74,8 @@ func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, driver neo4j return anthrovePost, exists, nil } -func CheckIfAnthrovePostNodeExistsBySourceURl(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthrovePost, bool, error) { +// AnthroveNodeExistsBySourceURL checks if a models.AnthrovePost exists by its sourceUrl. +func AnthroveNodeExistsBySourceURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthrovePost, bool, error) { query := ` OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {url: $source_url}]-() RETURN postNode.post_id AS AnthrovePostID @@ -90,7 +92,8 @@ func CheckIfAnthrovePostNodeExistsBySourceURl(ctx context.Context, driver neo4j. return anthrovePost, exists, nil } -func CheckIfAnthrovePostNodeExistsBySourceID(ctx context.Context, driver neo4j.DriverWithContext, sourcePostID string) (*models.AnthrovePost, bool, error) { +// AnthroveNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID. +func AnthroveNodeExistsBySourceID(ctx context.Context, driver neo4j.DriverWithContext, sourcePostID string) (*models.AnthrovePost, bool, error) { query := ` OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {source_post_id: $source_post_id}]-() RETURN postNode.post_id AS AnthrovePostID diff --git a/pkg/graph/post_impl.go b/pkg/graph/post_impl.go index 36ca715..ff7e506 100644 --- a/pkg/graph/post_impl.go +++ b/pkg/graph/post_impl.go @@ -18,16 +18,19 @@ func (g *graphConnection) DeletePost(ctx context.Context, anthrovePost *models.A } -func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) { - return internal.CheckIfAnthrovePostNodeExistsByAnthroveID(ctx, g.driver, anthrovePost) -} - -func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) { - return internal.CheckIfAnthrovePostNodeExistsBySourceURl(ctx, g.driver, sourceUrl) -} - +// CheckPostNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID. func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) { - return internal.CheckIfAnthrovePostNodeExistsBySourceID(ctx, g.driver, sourcePostID) + return internal.AnthroveNodeExistsBySourceID(ctx, g.driver, sourcePostID) +} + +// CheckPostNodeExistsByAnthroveID checks if a models.AnthrovePost exists by its models.AnthrovePostID. +func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) { + return internal.AnthroveNodeExistsByAnthroveID(ctx, g.driver, anthrovePost) +} + +// CheckPostNodeExistsBySourceURL checks if a models.AnthrovePost exists by its sourceUrl. +func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) { + return internal.AnthroveNodeExistsBySourceURL(ctx, g.driver, sourceUrl) } func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {