Compare commits
No commits in common. "e3a5adb2cc56b772c876d2f8ce4659fdc0afe5ac" and "22436a1d7784bc265909444724fbcaa498e4e9da" have entirely different histories.
e3a5adb2cc
...
22436a1d77
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.dragse.it/anthrove/otter-space-sdk
|
|||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/neo4j/neo4j-go-driver/v5 v5.20.0
|
github.com/neo4j/neo4j-go-driver/v5 v5.17.0
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
4
go.sum
4
go.sum
@ -1,8 +1,8 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/neo4j/neo4j-go-driver/v5 v5.20.0 h1:XnoAi6g6XRkX+wxWa3yM+f7PT2VUkGQfBGtGuJL4fsM=
|
github.com/neo4j/neo4j-go-driver/v5 v5.17.0 h1:Bdqg1Y8Hd3uLYToXtBjysDYXTdMiP7zeUNUEwfbJkSo=
|
||||||
github.com/neo4j/neo4j-go-driver/v5 v5.20.0/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k=
|
github.com/neo4j/neo4j-go-driver/v5 v5.17.0/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package utils
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package post
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -8,7 +8,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateAnthrovePostNode will always create a new node, it does not check if the node with the corresponding post_id and rating exists.
|
|
||||||
func CreateAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) error {
|
func CreateAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) error {
|
||||||
query := `
|
query := `
|
||||||
CREATE (newPostNode:AnthrovePost {post_id: $anthrove_post_id, rating: $anthrove_rating})
|
CREATE (newPostNode:AnthrovePost {post_id: $anthrove_post_id, rating: $anthrove_rating})
|
||||||
@ -32,31 +31,7 @@ func CreateAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAnthrovePostNode will always delete a node, it only needs the anthrovePost.PostID filled out.
|
func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
|
||||||
func DeleteAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) error {
|
|
||||||
query := `
|
|
||||||
MATCH (anthrovePost:AnthrovePost {post_id: $anthrove_post_id})
|
|
||||||
DELETE anthrovePost
|
|
||||||
`
|
|
||||||
|
|
||||||
params := map[string]any{
|
|
||||||
"anthrove_post_id": anthrovePost.PostID,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"anthrove_post_id": anthrovePost.PostID,
|
|
||||||
}).Trace("graph: deleted anthrove post")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 := `
|
query := `
|
||||||
OPTIONAL MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
OPTIONAL MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
||||||
RETURN postNode.post_id AS AnthrovePostID
|
RETURN postNode.post_id AS AnthrovePostID
|
||||||
@ -74,8 +49,7 @@ func AnthroveNodeExistsByAnthroveID(ctx context.Context, driver neo4j.DriverWith
|
|||||||
return anthrovePost, exists, nil
|
return anthrovePost, exists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnthroveNodeExistsBySourceURL checks if a models.AnthrovePost exists by its sourceUrl.
|
func CheckIfAnthrovePostNodeExistsBySourceURl(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthrovePost, bool, error) {
|
||||||
func AnthroveNodeExistsBySourceURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthrovePost, bool, error) {
|
|
||||||
query := `
|
query := `
|
||||||
OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {url: $source_url}]-()
|
OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {url: $source_url}]-()
|
||||||
RETURN postNode.post_id AS AnthrovePostID
|
RETURN postNode.post_id AS AnthrovePostID
|
||||||
@ -92,8 +66,7 @@ func AnthroveNodeExistsBySourceURL(ctx context.Context, driver neo4j.DriverWithC
|
|||||||
return anthrovePost, exists, nil
|
return anthrovePost, exists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnthroveNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID.
|
func CheckIfAnthrovePostNodeExistsBySourceID(ctx context.Context, driver neo4j.DriverWithContext, sourcePostID string) (*models.AnthrovePost, bool, error) {
|
||||||
func AnthroveNodeExistsBySourceID(ctx context.Context, driver neo4j.DriverWithContext, sourcePostID string) (*models.AnthrovePost, bool, error) {
|
|
||||||
query := `
|
query := `
|
||||||
OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {source_post_id: $source_post_id}]-()
|
OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {source_post_id: $source_post_id}]-()
|
||||||
RETURN postNode.post_id AS AnthrovePostID
|
RETURN postNode.post_id AS AnthrovePostID
|
@ -1,4 +1,4 @@
|
|||||||
package relations
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -9,8 +9,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateAnthrovePostToSourceLink establishes a link between a models.AnthrovePost and a models.AnthroveSource
|
func EstablishAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||||
func CreateAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
|
||||||
query := `
|
query := `
|
||||||
MATCH (sourceNode:Source {domain: $source_url})
|
MATCH (sourceNode:Source {domain: $source_url})
|
||||||
MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
@ -1,4 +1,4 @@
|
|||||||
package source
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -9,7 +9,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateSourceNode will always create a new node, it checks if a node with the same url exits and merges it.
|
|
||||||
func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthroveSource *models.AnthroveSource) error {
|
func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthroveSource *models.AnthroveSource) error {
|
||||||
query := `
|
query := `
|
||||||
MERGE (sourceNode:Source {domain: $source_url})
|
MERGE (sourceNode:Source {domain: $source_url})
|
||||||
@ -35,30 +34,6 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteSourceNode will delete a node with a given Domain
|
|
||||||
func DeleteSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthroveSource *models.AnthroveSource) error {
|
|
||||||
query := `
|
|
||||||
MERGE (sourceNode:Source {domain: $domain})
|
|
||||||
DELETE sourceNode
|
|
||||||
`
|
|
||||||
params := map[string]any{
|
|
||||||
"domain": anthroveSource.Domain,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("graph: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"node_source_url": anthroveSource.Domain,
|
|
||||||
"node_source_displayName": anthroveSource.DisplayName,
|
|
||||||
"node_source_icon": anthroveSource.Icon,
|
|
||||||
}).Trace("graph: created source node")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]models.AnthroveSource, error) {
|
func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]models.AnthroveSource, error) {
|
||||||
var sources []models.AnthroveSource
|
var sources []models.AnthroveSource
|
||||||
|
|
||||||
@ -100,8 +75,8 @@ func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]m
|
|||||||
return sources, nil
|
return sources, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSourceNodesByURL returns the first models.AnthroveSource provided by the database
|
|
||||||
func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthroveSource, error) {
|
func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthroveSource, error) {
|
||||||
|
|
||||||
var source models.AnthroveSource
|
var source models.AnthroveSource
|
||||||
|
|
||||||
query := `
|
query := `
|
@ -1,4 +1,4 @@
|
|||||||
package tag
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package user
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -217,8 +217,8 @@ func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthro
|
|||||||
userRelationships := make([]models.AnthroveUserRelationship, 0)
|
userRelationships := make([]models.AnthroveUserRelationship, 0)
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
MATCH (user:User{user_id: $anthrove_user_id})-[relations:HAS_ACCOUNT_AT]->(source:Source)
|
MATCH (user:User{user_id: $anthrove_user_id})-[relation:HAS_ACCOUNT_AT]->(source:Source)
|
||||||
RETURN user as User, relations as Relation, source as Source;
|
RETURN user as User, relation as Relation, source as Source;
|
||||||
`
|
`
|
||||||
params := map[string]any{
|
params := map[string]any{
|
||||||
"anthrove_user_id": anthroveUserID,
|
"anthrove_user_id": anthroveUserID,
|
@ -3,7 +3,7 @@ package graph
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/internal/utils"
|
"git.dragse.it/anthrove/otter-space-sdk/internal"
|
||||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
||||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
|
||||||
)
|
)
|
||||||
@ -37,6 +37,6 @@ func (g *graphConnection) Connect(ctx context.Context, endpoint string, username
|
|||||||
|
|
||||||
func logger(graphDebug bool) func(config *config.Config) {
|
func logger(graphDebug bool) func(config *config.Config) {
|
||||||
return func(config *config.Config) {
|
return func(config *config.Config) {
|
||||||
config.Log = utils.NewGraphLogger(graphDebug)
|
config.Log = internal.NewGraphLogger(graphDebug)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,16 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Post interface {
|
type Post interface {
|
||||||
|
|
||||||
// CreatePost will always create a new node, it does not check if the node with the corresponding post_id and rating exists.
|
|
||||||
CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
||||||
|
DeletePost() error
|
||||||
|
|
||||||
// DeletePost will always delete a node, it only needs the anthrovePost.PostID filled out.
|
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
|
||||||
DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
// It returns an error if the operation fails.
|
||||||
|
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) 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)
|
|
||||||
|
|
||||||
// CheckPostNodeExistsByAnthroveID checks if a post node exists in the OtterSpace graph by its Anthrove ID.
|
// 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.
|
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
|
||||||
@ -26,6 +21,7 @@ type Post interface {
|
|||||||
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
|
// 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)
|
CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error)
|
||||||
|
|
||||||
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
|
// CheckPostNodeExistsBySourceID checks if a post node exists in the OtterSpace graph by its source ID.
|
||||||
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error
|
// 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)
|
||||||
}
|
}
|
||||||
|
@ -2,39 +2,31 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"git.dragse.it/anthrove/otter-space-sdk/internal"
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/internal/post"
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/internal/relations"
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreatePost will always create a new node, it does not check if the node with the corresponding post_id and rating exists.
|
|
||||||
func (g *graphConnection) CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
|
func (g *graphConnection) CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
|
||||||
return post.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePost will always delete a node, it only needs the anthrovePost.PostID filled out.
|
func (g *graphConnection) DeletePost() error {
|
||||||
func (g *graphConnection) DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
|
//TODO implement me
|
||||||
return post.DeleteAnthrovePostNode(ctx, g.driver, anthrovePost)
|
panic("implement me")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckPostNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID.
|
|
||||||
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) {
|
|
||||||
return post.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) {
|
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
|
||||||
return post.AnthroveNodeExistsByAnthroveID(ctx, g.driver, anthrovePost)
|
return internal.CheckIfAnthrovePostNodeExistsByAnthroveID(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) {
|
func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) {
|
||||||
return post.AnthroveNodeExistsBySourceURL(ctx, g.driver, sourceUrl)
|
return internal.CheckIfAnthrovePostNodeExistsBySourceURl(ctx, g.driver, sourceUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinkPostWithSource establishes a link between a models.AnthrovePost and a models.AnthroveSource
|
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) {
|
||||||
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
return internal.CheckIfAnthrovePostNodeExistsBySourceID(ctx, g.driver, sourcePostID)
|
||||||
return relations.CreateAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,14 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Source interface {
|
type Source interface {
|
||||||
|
|
||||||
// CreateSource will always create a new node, it checks if a node with the same url exits and merges it.
|
|
||||||
CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
||||||
|
|
||||||
// DeleteSource will delete a node with a given Domain
|
|
||||||
DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
||||||
|
|
||||||
// GetSourceByURL returns the first models.AnthroveSource provided by the database
|
// GetSourceByURL returns the Source Node based on the URL
|
||||||
GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error)
|
GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error)
|
||||||
|
|
||||||
// GetSourceLinkForUser retrieves the links between a user and sources in the OtterSpace graph.
|
// GetSourceLinkForUser retrieves the links between a user and sources in the OtterSpace graph.
|
||||||
|
@ -2,35 +2,31 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"git.dragse.it/anthrove/otter-space-sdk/internal"
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/internal/source"
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/internal/user"
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateSource will always create a new node, it checks if a node with the same url exits and merges it.
|
|
||||||
func (g *graphConnection) CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
|
func (g *graphConnection) CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
|
||||||
return source.CreateSourceNode(ctx, g.driver, anthroveSource)
|
return internal.CreateSourceNode(ctx, g.driver, anthroveSource)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteSource will delete a node with a given Domain
|
|
||||||
func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
|
func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
|
||||||
return source.DeleteSourceNode(ctx, g.driver, anthroveSource)
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSourceByURL returns the first models.AnthroveSource provided by the database
|
|
||||||
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
|
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
|
||||||
return source.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
|
return internal.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
|
func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
|
||||||
return source.GetAllSourceNodes(ctx, g.driver)
|
return internal.GetAllSourceNodes(ctx, g.driver)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetSourceLinkForSpecifiedUser(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
|
func (g *graphConnection) GetSourceLinkForSpecifiedUser(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
|
||||||
return user.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
|
return internal.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetSourceLinkForUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) {
|
func (g *graphConnection) GetSourceLinkForUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) {
|
||||||
return user.GetUserSourceLink(ctx, g.driver, anthroveUserID)
|
return internal.GetUserSourceLink(ctx, g.driver, anthroveUserID)
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"git.dragse.it/anthrove/otter-space-sdk/internal"
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/internal/tag"
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,9 +17,9 @@ func (g *graphConnection) DeleteTag() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
|
func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
|
||||||
return tag.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
|
return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) {
|
func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) {
|
||||||
return tag.GetTags(ctx, g.driver)
|
return internal.GetTags(ctx, g.driver)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ type User interface {
|
|||||||
// It returns the user and an error if the operation fails.
|
// It returns the user and an error if the operation fails.
|
||||||
GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error)
|
GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error)
|
||||||
|
|
||||||
// GetUserFavoritePostsWithPagination gets all user favorites with relations and sources for the given user
|
// 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)
|
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 returns a list of Tags that the user hs favorites through a post
|
||||||
|
@ -3,9 +3,7 @@ package graph
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.dragse.it/anthrove/otter-space-sdk/internal"
|
||||||
"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"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,33 +18,33 @@ func (g *graphConnection) DeleteUser(ctx context.Context, anthroveUserID models.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
|
func (g *graphConnection) CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
|
||||||
return user.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
|
return internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
|
func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
|
||||||
return user.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
|
return internal.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) {
|
func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) {
|
||||||
return user.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
|
return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
|
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
|
||||||
return user.GetAnthroveUser(ctx, g.driver, anthroveUserID)
|
return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
||||||
return user.GetUserFavoritesCount(ctx, g.driver, anthroveUserID)
|
return internal.GetUserFavoritesCount(ctx, g.driver, anthroveUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
|
func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
|
||||||
return relations.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl)
|
return internal.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
|
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
|
||||||
return relations.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
|
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
||||||
return user.GetAllAnthroveUserIDs(ctx, g.driver)
|
return internal.GetAllAnthroveUserIDs(ctx, g.driver)
|
||||||
}
|
}
|
||||||
|
@ -13,3 +13,8 @@ type FavoritePost struct {
|
|||||||
type FavoriteList struct {
|
type FavoriteList struct {
|
||||||
Posts []FavoritePost `json:"posts,omitempty"`
|
Posts []FavoritePost `json:"posts,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TagsWithFrequency struct {
|
||||||
|
Frequency int64 `json:"frequency"`
|
||||||
|
Tags AnthroveTag `json:"tags"`
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthrovePost struct {
|
type AnthrovePost struct {
|
||||||
PostID AnthrovePostID `json:"post_id" format:"string"`
|
PostID AnthrovePostID `json:"post_id"`
|
||||||
Rating AnthroveRating `json:"rating" format:"string"`
|
Rating AnthroveRating `json:"rating"`
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthroveUserRelationship struct {
|
type AnthroveUserRelationship struct {
|
||||||
UserID string `json:"user_id" format:"string"`
|
UserID string `json:"user_id"`
|
||||||
Username string `json:"username" format:"string"`
|
Username string `json:"username"`
|
||||||
ScrapeTimeInterval string `json:"scrape_time_interval" format:"string"`
|
ScrapeTimeInterval string `json:"scrape_time_interval"`
|
||||||
Source AnthroveSource `json:"source"`
|
Source AnthroveSource `json:"source"`
|
||||||
}
|
}
|
||||||
type AnthrovePostRelationship struct {
|
type AnthrovePostRelationship struct {
|
||||||
PostID string `json:"post_id" format:"string"`
|
PostID string `json:"post_id"`
|
||||||
Url string `json:"url" format:"string"`
|
Url string `json:"url"`
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthroveSource struct {
|
type AnthroveSource struct {
|
||||||
DisplayName string `json:"display_name" format:"string"`
|
DisplayName string `json:"display_name"`
|
||||||
Domain string `json:"domain" format:"string"`
|
Domain string `json:"domain"`
|
||||||
Icon string `json:"icon" format:"string"`
|
Icon string `json:"icon"`
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthroveTag struct {
|
type AnthroveTag struct {
|
||||||
Name string `json:"name" format:"string"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type" format:"string"`
|
Type string `json:"type"`
|
||||||
}
|
|
||||||
|
|
||||||
type TagsWithFrequency struct {
|
|
||||||
Frequency int64 `json:"frequency"`
|
|
||||||
Tags AnthroveTag `json:"tags"`
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthroveUser struct {
|
type AnthroveUser struct {
|
||||||
UserID AnthroveUserID `json:"user_id" format:"string"`
|
UserID AnthroveUserID `json:"user_id"`
|
||||||
Relationship []AnthroveUserRelationship `json:"relationship"`
|
Relationship []AnthroveUserRelationship `json:"relationship"`
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user