Compare commits
13 Commits
22436a1d77
...
e3a5adb2cc
Author | SHA1 | Date | |
---|---|---|---|
e3a5adb2cc | |||
3e4560768b | |||
a61c300b74 | |||
1017eaf5b8 | |||
fc73377d86 | |||
1075d45cb7 | |||
6d15d99563 | |||
5446f49a35 | |||
ca69008607 | |||
6760948e73 | |||
6cabcf9beb | |||
0620d2919e | |||
aa26357fec |
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.17.0
|
github.com/neo4j/neo4j-go-driver/v5 v5.20.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.17.0 h1:Bdqg1Y8Hd3uLYToXtBjysDYXTdMiP7zeUNUEwfbJkSo=
|
github.com/neo4j/neo4j-go-driver/v5 v5.20.0 h1:XnoAi6g6XRkX+wxWa3yM+f7PT2VUkGQfBGtGuJL4fsM=
|
||||||
github.com/neo4j/neo4j-go-driver/v5 v5.17.0/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k=
|
github.com/neo4j/neo4j-go-driver/v5 v5.20.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 internal
|
package post
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -8,6 +8,7 @@ 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})
|
||||||
@ -31,7 +32,31 @@ func CreateAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
|
// DeleteAnthrovePostNode will always delete a node, it only needs the anthrovePost.PostID filled out.
|
||||||
|
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
|
||||||
@ -49,7 +74,8 @@ func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, driver neo4j
|
|||||||
return anthrovePost, exists, nil
|
return anthrovePost, exists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckIfAnthrovePostNodeExistsBySourceURl(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthrovePost, bool, error) {
|
// AnthroveNodeExistsBySourceURL checks if a models.AnthrovePost exists by its sourceUrl.
|
||||||
|
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
|
||||||
@ -66,7 +92,8 @@ func CheckIfAnthrovePostNodeExistsBySourceURl(ctx context.Context, driver neo4j.
|
|||||||
return anthrovePost, exists, nil
|
return anthrovePost, exists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckIfAnthrovePostNodeExistsBySourceID(ctx context.Context, driver neo4j.DriverWithContext, sourcePostID string) (*models.AnthrovePost, bool, error) {
|
// AnthroveNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID.
|
||||||
|
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 internal
|
package relations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -9,7 +9,8 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EstablishAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
// CreateAnthrovePostToSourceLink establishes a link between a models.AnthrovePost and a models.AnthroveSource
|
||||||
|
func CreateAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||||
query := `
|
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 internal
|
package source
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -9,6 +9,7 @@ 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})
|
||||||
@ -34,6 +35,30 @@ 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
|
||||||
|
|
||||||
@ -75,8 +100,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 internal
|
package tag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package internal
|
package user
|
||||||
|
|
||||||
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})-[relation:HAS_ACCOUNT_AT]->(source:Source)
|
MATCH (user:User{user_id: $anthrove_user_id})-[relations:HAS_ACCOUNT_AT]->(source:Source)
|
||||||
RETURN user as User, relation as Relation, source as Source;
|
RETURN user as User, relations as Relation, source as Source;
|
||||||
`
|
`
|
||||||
params := map[string]any{
|
params := map[string]any{
|
||||||
"anthrove_user_id": anthroveUserID,
|
"anthrove_user_id": anthroveUserID,
|
@ -1,4 +1,4 @@
|
|||||||
package internal
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -3,7 +3,7 @@ package graph
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/internal"
|
"git.dragse.it/anthrove/otter-space-sdk/internal/utils"
|
||||||
"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 = internal.NewGraphLogger(graphDebug)
|
config.Log = utils.NewGraphLogger(graphDebug)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,21 @@ 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(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
|
||||||
DeletePost() error
|
|
||||||
|
|
||||||
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
|
// CreatePost will always create a new node, it does not check if the node with the corresponding post_id and rating exists.
|
||||||
// It returns an error if the operation fails.
|
CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
||||||
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error
|
|
||||||
|
// DeletePost will always delete a node, it only needs the anthrovePost.PostID filled out.
|
||||||
|
DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) 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.
|
||||||
@ -21,7 +26,6 @@ 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)
|
||||||
|
|
||||||
// CheckPostNodeExistsBySourceID checks if a post node exists in the OtterSpace graph by its source ID.
|
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
|
||||||
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
|
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error
|
||||||
CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error)
|
|
||||||
}
|
}
|
||||||
|
@ -2,31 +2,39 @@ 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 internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
return post.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) DeletePost() error {
|
// DeletePost will always delete a node, it only needs the anthrovePost.PostID filled out.
|
||||||
//TODO implement me
|
func (g *graphConnection) DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
|
||||||
panic("implement me")
|
return post.DeleteAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckPostNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID.
|
||||||
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) {
|
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) {
|
||||||
return internal.CheckIfAnthrovePostNodeExistsBySourceID(ctx, g.driver, sourcePostID)
|
return post.AnthroveNodeExistsBySourceID(ctx, g.driver, sourcePostID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
// CheckPostNodeExistsByAnthroveID checks if a models.AnthrovePost exists by its models.AnthrovePostID.
|
||||||
return internal.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
|
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
|
||||||
|
return post.AnthroveNodeExistsByAnthroveID(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) {
|
||||||
|
return post.AnthroveNodeExistsBySourceURL(ctx, g.driver, sourceUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkPostWithSource establishes a link between a models.AnthrovePost and a models.AnthroveSource
|
||||||
|
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||||
|
return relations.CreateAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,19 @@ 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 Source Node based on the URL
|
// GetSourceByURL returns the first models.AnthroveSource provided by the database
|
||||||
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,31 +2,35 @@ 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 internal.CreateSourceNode(ctx, g.driver, anthroveSource)
|
return source.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 {
|
||||||
//TODO implement me
|
return source.DeleteSourceNode(ctx, g.driver, anthroveSource)
|
||||||
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 internal.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
|
return source.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 internal.GetAllSourceNodes(ctx, g.driver)
|
return source.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 internal.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
|
return user.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 internal.GetUserSourceLink(ctx, g.driver, anthroveUserID)
|
return user.GetUserSourceLink(ctx, g.driver, anthroveUserID)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,9 +18,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 internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
|
return tag.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 internal.GetTags(ctx, g.driver)
|
return tag.GetTags(ctx, g.driver)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package graph
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ type User interface {
|
|||||||
// It returns the user and an error if the operation fails.
|
// 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 relation and sources for the given user
|
// GetUserFavoritePostsWithPagination gets all user favorites with relations and sources for the given user
|
||||||
GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error)
|
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,7 +3,9 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,33 +20,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 internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
|
return user.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 internal.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
|
return user.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 internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
|
return user.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 internal.GetAnthroveUser(ctx, g.driver, anthroveUserID)
|
return user.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 internal.GetUserFavoritesCount(ctx, g.driver, anthroveUserID)
|
return user.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 internal.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl)
|
return relations.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
|
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
|
||||||
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
|
return relations.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 internal.GetAllAnthroveUserIDs(ctx, g.driver)
|
return user.GetAllAnthroveUserIDs(ctx, g.driver)
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,3 @@ 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"`
|
PostID AnthrovePostID `json:"post_id" format:"string"`
|
||||||
Rating AnthroveRating `json:"rating"`
|
Rating AnthroveRating `json:"rating" format:"string"`
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthroveUserRelationship struct {
|
type AnthroveUserRelationship struct {
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id" format:"string"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username" format:"string"`
|
||||||
ScrapeTimeInterval string `json:"scrape_time_interval"`
|
ScrapeTimeInterval string `json:"scrape_time_interval" format:"string"`
|
||||||
Source AnthroveSource `json:"source"`
|
Source AnthroveSource `json:"source"`
|
||||||
}
|
}
|
||||||
type AnthrovePostRelationship struct {
|
type AnthrovePostRelationship struct {
|
||||||
PostID string `json:"post_id"`
|
PostID string `json:"post_id" format:"string"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url" format:"string"`
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthroveSource struct {
|
type AnthroveSource struct {
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name" format:"string"`
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain" format:"string"`
|
||||||
Icon string `json:"icon"`
|
Icon string `json:"icon" format:"string"`
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type AnthroveTag struct {
|
type AnthroveTag struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name" format:"string"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type" format:"string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
UserID AnthroveUserID `json:"user_id" format:"string"`
|
||||||
Relationship []AnthroveUserRelationship `json:"relationship"`
|
Relationship []AnthroveUserRelationship `json:"relationship"`
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user