2024-02-16 14:54:36 +00:00
|
|
|
package pkg
|
2024-02-16 14:16:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-02-16 14:54:36 +00:00
|
|
|
"git.dragse.it/anthrove/anthrove-graph-sdk.git/internal"
|
2024-02-16 14:16:50 +00:00
|
|
|
"git.dragse.it/anthrove/anthrove-graph-sdk.git/pkg/models"
|
|
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
2024-02-16 14:54:36 +00:00
|
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
|
2024-02-16 14:16:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type graphConnection struct {
|
|
|
|
driver neo4j.DriverWithContext
|
2024-02-16 14:54:36 +00:00
|
|
|
graphDebug bool
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewGraphConnection(graphDebug bool) Graph {
|
|
|
|
return &graphConnection{
|
|
|
|
driver: nil,
|
2024-02-16 14:54:36 +00:00
|
|
|
graphDebug: graphDebug,
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) Connect(ctx context.Context, endpoint string, username string, password string) error {
|
2024-02-16 14:54:36 +00:00
|
|
|
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
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 15:16:57 +00:00
|
|
|
func (g *graphConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, error) {
|
2024-02-16 14:56:53 +00:00
|
|
|
return internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 15:16:57 +00:00
|
|
|
func (g *graphConnection) AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
|
2024-02-16 15:00:14 +00:00
|
|
|
return internal.CreateSourceNode(ctx, g.driver, anthroveSource)
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 15:16:57 +00:00
|
|
|
func (g *graphConnection) AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
|
2024-02-16 15:05:05 +00:00
|
|
|
return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 15:16:57 +00:00
|
|
|
func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID *models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
|
|
|
|
return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 16:21:26 +00:00
|
|
|
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)
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
|
2024-02-16 16:24:39 +00:00
|
|
|
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
|
2024-02-16 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) VerifyUserPostLink(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveUser *models.AnthroveUser) (bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, anthroveSource *models.AnthroveSource) (bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, anthroveSource *models.AnthroveSource) (bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUser *models.AnthroveUser) (int64, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) GetUserSourceLinks(ctx context.Context, anthroveUser *models.AnthroveUser) (map[string]models.AnthroveUserRelationship, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUser *models.AnthroveUser) (*models.AnthroveUser, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
2024-02-16 14:54:36 +00:00
|
|
|
|
|
|
|
func logger(graphDebug bool) func(config *config.Config) {
|
|
|
|
return func(config *config.Config) {
|
|
|
|
config.Log = internal.NewGraphLogger(graphDebug)
|
|
|
|
}
|
|
|
|
}
|