From 1017eaf5b86daf5b268227cc26c8ecfaf39cafe5 Mon Sep 17 00:00:00 2001 From: SoXX Date: Fri, 31 May 2024 15:24:05 +0200 Subject: [PATCH] docs(post): added function documentation Signed-off-by: SoXX --- internal/{relation => relations}/relationships.go | 5 +++-- internal/user/user.go | 4 ++-- pkg/graph/post_impl.go | 5 +++-- pkg/graph/user.go | 3 ++- pkg/graph/user_impl.go | 6 +++--- 5 files changed, 13 insertions(+), 10 deletions(-) rename internal/{relation => relations}/relationships.go (89%) diff --git a/internal/relation/relationships.go b/internal/relations/relationships.go similarity index 89% rename from internal/relation/relationships.go rename to internal/relations/relationships.go index b0d6a26..81856f7 100644 --- a/internal/relation/relationships.go +++ b/internal/relations/relationships.go @@ -1,4 +1,4 @@ -package relation +package relations import ( "context" @@ -9,7 +9,8 @@ import ( log "github.com/sirupsen/logrus" ) -func EstablishAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error { +// CreateAnthrovePostToSourceLink establishes a link between a models.AnthrovePost and a models.AnthroveSource +func CreateAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error { query := ` MATCH (sourceNode:Source {domain: $source_url}) MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id}) diff --git a/internal/user/user.go b/internal/user/user.go index ec66e61..6439149 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -217,8 +217,8 @@ func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthro userRelationships := make([]models.AnthroveUserRelationship, 0) query := ` - MATCH (user:User{user_id: $anthrove_user_id})-[relation:HAS_ACCOUNT_AT]->(source:Source) - RETURN user as User, relation as Relation, source as Source; + MATCH (user:User{user_id: $anthrove_user_id})-[relations:HAS_ACCOUNT_AT]->(source:Source) + RETURN user as User, relations as Relation, source as Source; ` params := map[string]any{ "anthrove_user_id": anthroveUserID, diff --git a/pkg/graph/post_impl.go b/pkg/graph/post_impl.go index e6cc558..1cef4ee 100644 --- a/pkg/graph/post_impl.go +++ b/pkg/graph/post_impl.go @@ -4,7 +4,7 @@ import ( "context" "git.dragse.it/anthrove/otter-space-sdk/internal/post" - "git.dragse.it/anthrove/otter-space-sdk/internal/relation" + "git.dragse.it/anthrove/otter-space-sdk/internal/relations" "git.dragse.it/anthrove/otter-space-sdk/pkg/models" ) @@ -34,6 +34,7 @@ func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, so return post.AnthroveNodeExistsBySourceURL(ctx, g.driver, sourceUrl) } +// LinkPostWithSource establishes a link between a models.AnthrovePost and a models.AnthroveSource func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error { - return relation.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship) + return relations.CreateAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship) } diff --git a/pkg/graph/user.go b/pkg/graph/user.go index e0aa8d3..ac70d3d 100644 --- a/pkg/graph/user.go +++ b/pkg/graph/user.go @@ -2,6 +2,7 @@ package graph import ( "context" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" ) @@ -27,7 +28,7 @@ type User interface { // It returns the user and an error if the operation fails. GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) - // GetUserFavoritePostsWithPagination gets all user favorites with relation and sources for the given user + // GetUserFavoritePostsWithPagination gets all user favorites with relations and sources for the given user GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) // GetUserTagsTroughFavedPosts returns a list of Tags that the user hs favorites through a post diff --git a/pkg/graph/user_impl.go b/pkg/graph/user_impl.go index fdc58b5..720896f 100644 --- a/pkg/graph/user_impl.go +++ b/pkg/graph/user_impl.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "git.dragse.it/anthrove/otter-space-sdk/internal/relation" + "git.dragse.it/anthrove/otter-space-sdk/internal/relations" "git.dragse.it/anthrove/otter-space-sdk/internal/user" "git.dragse.it/anthrove/otter-space-sdk/pkg/models" ) @@ -40,11 +40,11 @@ func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUser } func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) { - return relation.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl) + return relations.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl) } func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error { - return relation.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost) + return relations.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost) } func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {