refactor: breaking changes in this one!
This commit is contained in:
parent
63b92c22c8
commit
776cd9a32f
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
42
pkg/graph/graph_impl.go
Normal file
42
pkg/graph/graph_impl.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
27
pkg/graph/post.go
Normal file
27
pkg/graph/post.go
Normal file
@ -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)
|
||||
}
|
32
pkg/graph/post_impl.go
Normal file
32
pkg/graph/post_impl.go
Normal file
@ -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)
|
||||
}
|
25
pkg/graph/source.go
Normal file
25
pkg/graph/source.go
Normal file
@ -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)
|
||||
}
|
32
pkg/graph/source_impl.go
Normal file
32
pkg/graph/source_impl.go
Normal file
@ -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)
|
||||
}
|
18
pkg/graph/tag.go
Normal file
18
pkg/graph/tag.go
Normal file
@ -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)
|
||||
}
|
25
pkg/graph/tag_impl.go
Normal file
25
pkg/graph/tag_impl.go
Normal file
@ -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)
|
||||
}
|
39
pkg/graph/user.go
Normal file
39
pkg/graph/user.go
Normal file
@ -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)
|
||||
}
|
50
pkg/graph/user_impl.go
Normal file
50
pkg/graph/user_impl.go
Normal file
@ -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)
|
||||
}
|
Reference in New Issue
Block a user