From 776cd9a32f065cda0c523881f5d43fdb0e2d1908 Mon Sep 17 00:00:00 2001 From: SoXX Date: Tue, 28 May 2024 21:21:08 +0200 Subject: [PATCH] refactor: breaking changes in this one! --- internal/user.go | 3 +- pkg/graph/graph.go | 81 ++------------------------ pkg/graph/graph_impl.go | 42 +++++++++++++ pkg/graph/impl.go | 123 --------------------------------------- pkg/graph/post.go | 27 +++++++++ pkg/graph/post_impl.go | 32 ++++++++++ pkg/graph/source.go | 25 ++++++++ pkg/graph/source_impl.go | 32 ++++++++++ pkg/graph/tag.go | 18 ++++++ pkg/graph/tag_impl.go | 25 ++++++++ pkg/graph/user.go | 39 +++++++++++++ pkg/graph/user_impl.go | 50 ++++++++++++++++ 12 files changed, 296 insertions(+), 201 deletions(-) create mode 100644 pkg/graph/graph_impl.go delete mode 100644 pkg/graph/impl.go create mode 100644 pkg/graph/post.go create mode 100644 pkg/graph/post_impl.go create mode 100644 pkg/graph/source.go create mode 100644 pkg/graph/source_impl.go create mode 100644 pkg/graph/tag.go create mode 100644 pkg/graph/tag_impl.go create mode 100644 pkg/graph/user.go create mode 100644 pkg/graph/user_impl.go diff --git a/internal/user.go b/internal/user.go index a1128ec..f8f50c1 100644 --- a/internal/user.go +++ b/internal/user.go @@ -12,9 +12,8 @@ import ( func CreateUserNodeWithSourceRelation(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error { query := ` - MATCH (userNode:User {user_id: $anthrove_user_id}) MATCH (sourceNode:Source {domain: $source_domain}) - MERGE (userNode)-[r:HAS_ACCOUNT_AT {username: $source_user_name, user_id: $source_user_id}]->(sourceNode) + MERGE (userNode {user_id: $anthrove_user_id})-[r:HAS_ACCOUNT_AT {username: $source_user_name, user_id: $source_user_id}]->(sourceNode) ` params := map[string]any{ "anthrove_user_id": anthroveUserID, diff --git a/pkg/graph/graph.go b/pkg/graph/graph.go index 3cd7630..4a79eb7 100644 --- a/pkg/graph/graph.go +++ b/pkg/graph/graph.go @@ -27,90 +27,19 @@ package graph import ( "context" - - "git.dragse.it/anthrove/otter-space-sdk/pkg/models" ) // OtterSpace provides an interface for interacting with the OtterSpace API. // It includes methods for connecting to the API, adding and linking users, posts, and sources, // and retrieving information about users and posts. type OtterSpace interface { + // Connect sets up a connection to the OtterSpace API endpoint using the provided username and password. // It returns an error if the connection cannot be established. Connect(ctx context.Context, endpoint string, username string, password string) error - // AddUserWithRelationToSource adds a new user to the OtterSpace graph and associates them with a source. - // It returns the newly created user and an error if the operation fails. - AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error - - // AddSource adds a new source to the OtterSpace graph. - // It returns an error if the operation fails. - AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error - - // AddPost adds a new post to the OtterSpace graph. - // It returns an error if the operation fails. - AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error - - // AddTagWithRelationToPost adds a new tag to the OtterSpace graph and associates it with a post. - // It returns an error if the operation fails. - AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error - - // LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph. - // It returns an error if the operation fails. - LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error - - // LinkUserWithPost establishes a link between a user and a post in the OtterSpace graph. - // It returns an error if the operation fails. - LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error - - // CheckUserPostLink checks if a link between a user and a post exists in the OtterSpace graph. - // It returns true if the link exists, false otherwise, and an error if the operation fails. - CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) - - // CheckPostNodeExistsByAnthroveID checks if a post node exists in the OtterSpace graph by its Anthrove ID. - // It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails. - CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) - - // CheckPostNodeExistsBySourceURL checks if a post node exists in the OtterSpace graph by its source URL. - // It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails. - CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) - - // CheckPostNodeExistsBySourceID checks if a post node exists in the OtterSpace graph by its source ID. - // It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails. - CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) - - // GetUserFavoriteCount retrieves the count of a user's favorite posts from the OtterSpace graph. - // It returns the count and an error if the operation fails. - GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) - - // GetUserSourceLinks retrieves the links between a user and sources in the OtterSpace graph. - // It returns a map of source domains to user-source relationships, and an error if the operation fails. - GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) - - // GetSpecifiedUserSourceLink GetUserSourceLinks retrieves the links between a user and a specific source in the OtterSpace graph. - // It returns a map of source domains to user-source relationships, and an error if the operation fails. - GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) - - // GetAnthroveUser retrieves a user from the OtterSpace graph by their ID. - // It returns the user and an error if the operation fails. - GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) - - // GetAllAnthroveUserIDs retrieves all user IDs from the OtterSpace graph. - // It returns a slice of user IDs and an error if the operation fails. - GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) - - // GetUserFavoritePostsWithPagination gets all user favorites with relation 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 - GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) - - // GetAllTags returns a list of Tags that the user hs favorites through a post - GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) - - // GetAllSources returns a list of Sources in the database - GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) - - // GetSourceByURL returns the Source Node based on the URL - GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) + User + Tag + Source + Post } diff --git a/pkg/graph/graph_impl.go b/pkg/graph/graph_impl.go new file mode 100644 index 0000000..a01b58b --- /dev/null +++ b/pkg/graph/graph_impl.go @@ -0,0 +1,42 @@ +package graph + +import ( + "context" + + "git.dragse.it/anthrove/otter-space-sdk/internal" + "github.com/neo4j/neo4j-go-driver/v5/neo4j" + "github.com/neo4j/neo4j-go-driver/v5/neo4j/config" +) + +type graphConnection struct { + driver neo4j.DriverWithContext + graphDebug bool +} + +func NewGraphConnection(graphDebug bool) OtterSpace { + return &graphConnection{ + driver: nil, + graphDebug: graphDebug, + } +} + +func (g *graphConnection) Connect(ctx context.Context, endpoint string, username string, password string) error { + driver, err := neo4j.NewDriverWithContext(endpoint, neo4j.BasicAuth(username, password, ""), + logger(g.graphDebug)) + + if err != nil { + return err + } + err = driver.VerifyAuthentication(ctx, nil) + if err != nil { + return err + } + g.driver = driver + return nil +} + +func logger(graphDebug bool) func(config *config.Config) { + return func(config *config.Config) { + config.Log = internal.NewGraphLogger(graphDebug) + } +} diff --git a/pkg/graph/impl.go b/pkg/graph/impl.go deleted file mode 100644 index 6b1b3bb..0000000 --- a/pkg/graph/impl.go +++ /dev/null @@ -1,123 +0,0 @@ -package graph - -import ( - "context" - - "git.dragse.it/anthrove/otter-space-sdk/internal" - "git.dragse.it/anthrove/otter-space-sdk/pkg/models" - "github.com/neo4j/neo4j-go-driver/v5/neo4j" - "github.com/neo4j/neo4j-go-driver/v5/neo4j/config" -) - -type graphConnection struct { - driver neo4j.DriverWithContext - graphDebug bool -} - -func NewGraphConnection(graphDebug bool) OtterSpace { - return &graphConnection{ - driver: nil, - graphDebug: graphDebug, - } -} - -func (g *graphConnection) Connect(ctx context.Context, endpoint string, username string, password string) error { - driver, err := neo4j.NewDriverWithContext(endpoint, neo4j.BasicAuth(username, password, ""), - logger(g.graphDebug)) - - if err != nil { - return err - } - err = driver.VerifyAuthentication(ctx, nil) - if err != nil { - return err - } - g.driver = driver - return nil -} - -func (g *graphConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error { - return internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username) -} - -func (g *graphConnection) AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error { - return internal.CreateSourceNode(ctx, g.driver, anthroveSource) -} - -func (g *graphConnection) AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error { - return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost) -} - -func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error { - return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag) -} - -func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error { - return internal.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship) -} - -func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error { - return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost) -} - -func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) { - return internal.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl) -} - -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) -} - -func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) { - return internal.CheckIfAnthrovePostNodeExistsBySourceID(ctx, g.driver, sourcePostID) -} - -func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) { - return internal.GetUserFavoritesCount(ctx, g.driver, anthroveUserID) -} - -func (g *graphConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) { - return internal.GetUserSourceLink(ctx, g.driver, anthroveUserID) -} - -func (g *graphConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) { - return internal.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName) -} - -func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) { - return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID) -} - -func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) { - return internal.GetAllAnthroveUserIDs(ctx, g.driver) -} - -func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) { - return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit) -} - -func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) { - return internal.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID) -} - -func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) { - return internal.GetTags(ctx, g.driver) -} - -func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) { - return internal.GetAllSourceNodes(ctx, g.driver) -} - -func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) { - return internal.GetSourceNodesByURL(ctx, g.driver, sourceUrl) -} - -func logger(graphDebug bool) func(config *config.Config) { - return func(config *config.Config) { - config.Log = internal.NewGraphLogger(graphDebug) - } -} diff --git a/pkg/graph/post.go b/pkg/graph/post.go new file mode 100644 index 0000000..cdb7db3 --- /dev/null +++ b/pkg/graph/post.go @@ -0,0 +1,27 @@ +package graph + +import ( + "context" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +type Post interface { + CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error + DeletePost() error + + // LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph. + // It returns an error if the operation fails. + LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error + + // CheckPostNodeExistsByAnthroveID checks if a post node exists in the OtterSpace graph by its Anthrove ID. + // It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails. + CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) + + // CheckPostNodeExistsBySourceURL checks if a post node exists in the OtterSpace graph by its source URL. + // It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails. + CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) + + // CheckPostNodeExistsBySourceID checks if a post node exists in the OtterSpace graph by its source ID. + // It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails. + CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) +} diff --git a/pkg/graph/post_impl.go b/pkg/graph/post_impl.go new file mode 100644 index 0000000..6331a35 --- /dev/null +++ b/pkg/graph/post_impl.go @@ -0,0 +1,32 @@ +package graph + +import ( + "context" + "git.dragse.it/anthrove/otter-space-sdk/internal" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +func (g *graphConnection) CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error { + return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost) +} + +func (g *graphConnection) DeletePost() error { + //TODO implement me + panic("implement me") +} + +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) +} + +func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) { + return internal.CheckIfAnthrovePostNodeExistsBySourceID(ctx, g.driver, sourcePostID) +} + +func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error { + return internal.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship) +} diff --git a/pkg/graph/source.go b/pkg/graph/source.go new file mode 100644 index 0000000..7968cdd --- /dev/null +++ b/pkg/graph/source.go @@ -0,0 +1,25 @@ +package graph + +import ( + "context" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +type Source interface { + CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error + DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error + + // GetSourceByURL returns the Source Node based on the URL + GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) + + // GetSourceLinkForUser retrieves the links between a user and sources in the OtterSpace graph. + // It returns a map of source domains to user-source relationships, and an error if the operation fails. + GetSourceLinkForUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) + + // GetSourceLinkForSpecifiedUser GetSourceLinkForUser retrieves the links between a user and a specific source in the OtterSpace graph. + // It returns a map of source domains to user-source relationships, and an error if the operation fails. + GetSourceLinkForSpecifiedUser(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) + + // GetAllSources returns a list of Sources in the database + GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) +} diff --git a/pkg/graph/source_impl.go b/pkg/graph/source_impl.go new file mode 100644 index 0000000..4aaab61 --- /dev/null +++ b/pkg/graph/source_impl.go @@ -0,0 +1,32 @@ +package graph + +import ( + "context" + "git.dragse.it/anthrove/otter-space-sdk/internal" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +func (g *graphConnection) CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error { + return internal.CreateSourceNode(ctx, g.driver, anthroveSource) +} + +func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error { + //TODO implement me + panic("implement me") +} + +func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) { + return internal.GetSourceNodesByURL(ctx, g.driver, sourceUrl) +} + +func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) { + return internal.GetAllSourceNodes(ctx, g.driver) +} + +func (g *graphConnection) GetSourceLinkForSpecifiedUser(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) { + return internal.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName) +} + +func (g *graphConnection) GetSourceLinkForUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) { + return internal.GetUserSourceLink(ctx, g.driver, anthroveUserID) +} diff --git a/pkg/graph/tag.go b/pkg/graph/tag.go new file mode 100644 index 0000000..a1152f2 --- /dev/null +++ b/pkg/graph/tag.go @@ -0,0 +1,18 @@ +package graph + +import ( + "context" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +type Tag interface { + AddTag() error + DeleteTag() error + + // AddTagWithRelationToPost adds a new tag to the OtterSpace graph and associates it with a post. + // It returns an error if the operation fails. + AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error + + // GetAllTags returns a list of Tags that the user hs favorites through a post + GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) +} diff --git a/pkg/graph/tag_impl.go b/pkg/graph/tag_impl.go new file mode 100644 index 0000000..14a78d8 --- /dev/null +++ b/pkg/graph/tag_impl.go @@ -0,0 +1,25 @@ +package graph + +import ( + "context" + "git.dragse.it/anthrove/otter-space-sdk/internal" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +func (g *graphConnection) AddTag() error { + //TODO implement me + panic("implement me") +} + +func (g *graphConnection) DeleteTag() error { + //TODO implement me + panic("implement me") +} + +func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error { + return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag) +} + +func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) { + return internal.GetTags(ctx, g.driver) +} diff --git a/pkg/graph/user.go b/pkg/graph/user.go new file mode 100644 index 0000000..e0aa8d3 --- /dev/null +++ b/pkg/graph/user.go @@ -0,0 +1,39 @@ +package graph + +import ( + "context" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +type User interface { + CreateUser(ctx context.Context, anthroveUserID models.AnthroveUserID) error + DeleteUser(ctx context.Context, anthroveUserID models.AnthroveUserID) error + + // CreateUserWithRelationToSource will create or get a user to link it with a given source. + CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error + + // LinkUserWithPost creates a link between a user and a post in the OtterSpace graph. + LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error + + // CheckUserPostLink checks if a link between a user and a post exists in the OtterSpace graph. + // It returns true if the link exists, false otherwise, and an error if the operation fails. + CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) + + // GetUserFavoriteCount retrieves the count of a user's favorite posts from the OtterSpace graph. + // It returns the count and an error if the operation fails. + GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) + + // GetAnthroveUser retrieves a user from the OtterSpace graph by their ID. + // 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(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 + GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) + + // GetAllAnthroveUserIDs retrieves all user IDs from the OtterSpace graph. + // It returns a slice of user IDs and an error if the operation fails. + GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) +} diff --git a/pkg/graph/user_impl.go b/pkg/graph/user_impl.go new file mode 100644 index 0000000..a383b73 --- /dev/null +++ b/pkg/graph/user_impl.go @@ -0,0 +1,50 @@ +package graph + +import ( + "context" + "fmt" + "git.dragse.it/anthrove/otter-space-sdk/internal" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" +) + +func (g *graphConnection) CreateUser(ctx context.Context, anthroveUserID models.AnthroveUserID) error { + //TODO implement me + return fmt.Errorf("not implemented! Use the CreateUserWithRelationToSource function to create a user") +} + +func (g *graphConnection) DeleteUser(ctx context.Context, anthroveUserID models.AnthroveUserID) error { + //TODO implement me + return fmt.Errorf("not implemented") +} + +func (g *graphConnection) CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error { + return internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username) +} + +func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) { + return internal.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID) +} + +func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) { + return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit) +} + +func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) { + return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID) +} + +func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) { + return internal.GetUserFavoritesCount(ctx, g.driver, anthroveUserID) +} + +func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) { + return internal.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl) +} + +func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error { + return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost) +} + +func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) { + return internal.GetAllAnthroveUserIDs(ctx, g.driver) +}