Compare commits
17 Commits
main
...
develop/ma
Author | SHA1 | Date | |
---|---|---|---|
c242a2b57a | |||
76f3c8d97e | |||
e3a5adb2cc | |||
3e4560768b | |||
a61c300b74 | |||
1017eaf5b8 | |||
fc73377d86 | |||
1075d45cb7 | |||
6d15d99563 | |||
5446f49a35 | |||
ca69008607 | |||
6760948e73 | |||
6cabcf9beb | |||
0620d2919e | |||
aa26357fec | |||
22436a1d77 | |||
776cd9a32f |
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.dragse.it/anthrove/otter-space-sdk
|
||||
go 1.22.0
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
|
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
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.17.0/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k=
|
||||
github.com/neo4j/neo4j-go-driver/v5 v5.20.0 h1:XnoAi6g6XRkX+wxWa3yM+f7PT2VUkGQfBGtGuJL4fsM=
|
||||
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
|
@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -8,6 +8,7 @@ import (
|
||||
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 {
|
||||
query := `
|
||||
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
|
||||
}
|
||||
|
||||
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 := `
|
||||
OPTIONAL MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
||||
RETURN postNode.post_id AS AnthrovePostID
|
||||
@ -49,7 +74,8 @@ func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, driver neo4j
|
||||
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 := `
|
||||
OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {url: $source_url}]-()
|
||||
RETURN postNode.post_id AS AnthrovePostID
|
||||
@ -66,7 +92,8 @@ func CheckIfAnthrovePostNodeExistsBySourceURl(ctx context.Context, driver neo4j.
|
||||
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 := `
|
||||
OPTIONAL MATCH (postNode:AnthrovePost)<-[:REFERENCE {source_post_id: $source_post_id}]-()
|
||||
RETURN postNode.post_id AS AnthrovePostID
|
@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package relations
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -9,7 +9,8 @@ import (
|
||||
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 models.AnthroveSourceDomain, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||
query := `
|
||||
MATCH (sourceNode:Source {domain: $source_url})
|
||||
MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package source
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -9,6 +9,7 @@ import (
|
||||
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 {
|
||||
query := `
|
||||
MERGE (sourceNode:Source {domain: $source_url})
|
||||
@ -34,6 +35,30 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr
|
||||
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) {
|
||||
var sources []models.AnthroveSource
|
||||
|
||||
@ -61,9 +86,9 @@ func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]m
|
||||
}
|
||||
|
||||
sources = append(sources, models.AnthroveSource{
|
||||
DisplayName: source.Props["display_name"].(string),
|
||||
Domain: source.Props["domain"].(string),
|
||||
Icon: source.Props["icon"].(string),
|
||||
DisplayName: models.AnthroveSourceDisplayName(source.Props["display_name"].(string)),
|
||||
Domain: models.AnthroveSourceDomain(source.Props["domain"].(string)),
|
||||
Icon: models.AnthroveSourceIcon(source.Props["icon"].(string)),
|
||||
})
|
||||
|
||||
}
|
||||
@ -75,8 +100,8 @@ func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]m
|
||||
return sources, nil
|
||||
}
|
||||
|
||||
func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthroveSource, error) {
|
||||
|
||||
// GetSourceNodesByURL returns the first models.AnthroveSource provided by the database
|
||||
func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl models.AnthroveSourceDomain) (*models.AnthroveSource, error) {
|
||||
var source models.AnthroveSource
|
||||
|
||||
query := `
|
||||
@ -101,9 +126,9 @@ func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, so
|
||||
return nil, err
|
||||
}
|
||||
|
||||
source.DisplayName = record.Props["display_name"].(string)
|
||||
source.Domain = record.Props["domain"].(string)
|
||||
source.Icon = record.Props["icon"].(string)
|
||||
source.DisplayName = models.AnthroveSourceDisplayName(record.Props["display_name"].(string))
|
||||
source.Domain = models.AnthroveSourceDomain(record.Props["domain"].(string))
|
||||
source.Icon = models.AnthroveSourceIcon(record.Props["icon"].(string))
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"source_url": sourceUrl,
|
@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package tag
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -10,11 +10,10 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func CreateUserNodeWithSourceRelation(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
|
||||
func CreateUserNodeWithSourceRelation(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDomain models.AnthroveSourceDomain, 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 (:User {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,
|
||||
@ -134,9 +133,9 @@ func GetUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anth
|
||||
UserID: sourceUserID,
|
||||
Username: sourceUsername,
|
||||
Source: models.AnthroveSource{
|
||||
DisplayName: displayName,
|
||||
Domain: domain,
|
||||
Icon: icon,
|
||||
DisplayName: models.AnthroveSourceDisplayName(displayName),
|
||||
Domain: models.AnthroveSourceDomain(domain),
|
||||
Icon: models.AnthroveSourceIcon(icon),
|
||||
},
|
||||
}
|
||||
userSource[displayName] = anthroveSourceUser
|
||||
@ -150,7 +149,7 @@ func GetUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anth
|
||||
return userSource, nil
|
||||
}
|
||||
|
||||
func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
|
||||
func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDisplayName models.AnthroveSourceDisplayName) (map[string]models.AnthroveUserRelationship, error) {
|
||||
|
||||
userSource := make(map[string]models.AnthroveUserRelationship)
|
||||
|
||||
@ -195,9 +194,9 @@ func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithCont
|
||||
UserID: sourceUserID,
|
||||
Username: sourceUsername,
|
||||
Source: models.AnthroveSource{
|
||||
DisplayName: displayName,
|
||||
Domain: domain,
|
||||
Icon: icon,
|
||||
DisplayName: models.AnthroveSourceDisplayName(displayName),
|
||||
Domain: models.AnthroveSourceDomain(domain),
|
||||
Icon: models.AnthroveSourceIcon(icon),
|
||||
},
|
||||
}
|
||||
userSource[displayName] = anthroveSourceUser
|
||||
@ -218,8 +217,8 @@ func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthro
|
||||
userRelationships := make([]models.AnthroveUserRelationship, 0)
|
||||
|
||||
query := `
|
||||
MATCH (user:User{user_id: $anthrove_user_id})-[relation:HAS_ACCOUNT_AT]->(source:Source)
|
||||
RETURN user as User, relation as Relation, source as Source;
|
||||
MATCH (user:User{user_id: $anthrove_user_id})-[relations:HAS_ACCOUNT_AT]->(source:Source)
|
||||
RETURN user as User, relations as Relation, source as Source;
|
||||
`
|
||||
params := map[string]any{
|
||||
"anthrove_user_id": anthroveUserID,
|
||||
@ -257,9 +256,9 @@ func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthro
|
||||
})
|
||||
|
||||
userSources = models.AnthroveSource{
|
||||
DisplayName: utils.GetOrDefault(source.Props, "display_name", "").(string),
|
||||
Domain: utils.GetOrDefault(source.Props, "domain", "").(string),
|
||||
Icon: utils.GetOrDefault(source.Props, "icon", "").(string),
|
||||
DisplayName: models.AnthroveSourceDisplayName(utils.GetOrDefault(source.Props, "display_name", "").(string)),
|
||||
Domain: models.AnthroveSourceDomain(utils.GetOrDefault(source.Props, "domain", "").(string)),
|
||||
Icon: models.AnthroveSourceIcon(utils.GetOrDefault(source.Props, "icon", "").(string)),
|
||||
}
|
||||
|
||||
anthroveUser.UserID = models.AnthroveUserID(utils.GetOrDefault(user.Props, "user_id", "").(string))
|
@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -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/utils"
|
||||
"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 = utils.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)
|
||||
}
|
||||
}
|
31
pkg/graph/post.go
Normal file
31
pkg/graph/post.go
Normal file
@ -0,0 +1,31 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
// 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.
|
||||
// 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)
|
||||
|
||||
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
|
||||
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain models.AnthroveSourceDomain, anthrovePostRelationship *models.AnthrovePostRelationship) error
|
||||
}
|
40
pkg/graph/post_impl.go
Normal file
40
pkg/graph/post_impl.go
Normal file
@ -0,0 +1,40 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
return post.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||
}
|
||||
|
||||
// DeletePost will always delete a node, it only needs the anthrovePost.PostID filled out.
|
||||
func (g *graphConnection) DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
|
||||
return post.DeleteAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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 models.AnthroveSourceDomain, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||
return relations.CreateAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
|
||||
}
|
30
pkg/graph/source.go
Normal file
30
pkg/graph/source.go
Normal file
@ -0,0 +1,30 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
// DeleteSource will delete a node with a given Domain
|
||||
DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
||||
|
||||
// GetSourceByURL returns the first models.AnthroveSource provided by the database
|
||||
GetSourceByURL(ctx context.Context, sourceUrl models.AnthroveSourceDomain) (*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 models.AnthroveSourceDisplayName) (map[string]models.AnthroveUserRelationship, error)
|
||||
|
||||
// GetAllSources returns a list of Sources in the database
|
||||
GetAllSources(ctx context.Context) ([]models.AnthroveSource, error)
|
||||
}
|
36
pkg/graph/source_impl.go
Normal file
36
pkg/graph/source_impl.go
Normal file
@ -0,0 +1,36 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
return source.DeleteSourceNode(ctx, g.driver, anthroveSource)
|
||||
}
|
||||
|
||||
// GetSourceByURL returns the first models.AnthroveSource provided by the database
|
||||
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl models.AnthroveSourceDomain) (*models.AnthroveSource, error) {
|
||||
return source.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
|
||||
return source.GetAllSourceNodes(ctx, g.driver)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetSourceLinkForSpecifiedUser(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName models.AnthroveSourceDisplayName) (map[string]models.AnthroveUserRelationship, error) {
|
||||
return user.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetSourceLinkForUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) {
|
||||
return user.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)
|
||||
}
|
26
pkg/graph/tag_impl.go
Normal file
26
pkg/graph/tag_impl.go
Normal file
@ -0,0 +1,26 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.dragse.it/anthrove/otter-space-sdk/internal/tag"
|
||||
"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 tag.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) {
|
||||
return tag.GetTags(ctx, g.driver)
|
||||
}
|
40
pkg/graph/user.go
Normal file
40
pkg/graph/user.go
Normal file
@ -0,0 +1,40 @@
|
||||
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 models.AnthroveSourceDomain, 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 relations 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)
|
||||
}
|
52
pkg/graph/user_impl.go
Normal file
52
pkg/graph/user_impl.go
Normal file
@ -0,0 +1,52 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
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 models.AnthroveSourceDomain, userID string, username string) error {
|
||||
return user.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
|
||||
return user.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
|
||||
return user.GetAnthroveUser(ctx, g.driver, anthroveUserID)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
||||
return user.GetUserFavoritesCount(ctx, g.driver, anthroveUserID)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
|
||||
return relations.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
||||
return user.GetAllAnthroveUserIDs(ctx, g.driver)
|
||||
}
|
@ -3,6 +3,9 @@ package models
|
||||
type AnthroveUserID string
|
||||
type AnthrovePostID string
|
||||
type AnthroveRating string
|
||||
type AnthroveSourceDomain string
|
||||
type AnthroveSourceIcon string
|
||||
type AnthroveSourceDisplayName string
|
||||
|
||||
const (
|
||||
SFW AnthroveRating = "s"
|
||||
|
@ -13,8 +13,3 @@ type FavoritePost struct {
|
||||
type FavoriteList struct {
|
||||
Posts []FavoritePost `json:"posts,omitempty"`
|
||||
}
|
||||
|
||||
type TagsWithFrequency struct {
|
||||
Frequency int64 `json:"frequency"`
|
||||
Tags AnthroveTag `json:"tags"`
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
type AnthrovePost struct {
|
||||
PostID AnthrovePostID `json:"post_id"`
|
||||
Rating AnthroveRating `json:"rating"`
|
||||
PostID AnthrovePostID `json:"post_id" format:"string"`
|
||||
Rating AnthroveRating `json:"rating" format:"string"`
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package models
|
||||
|
||||
type AnthroveUserRelationship struct {
|
||||
UserID string `json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
ScrapeTimeInterval string `json:"scrape_time_interval"`
|
||||
UserID string `json:"user_id" format:"string"`
|
||||
Username string `json:"username" format:"string"`
|
||||
ScrapeTimeInterval string `json:"scrape_time_interval" format:"string"`
|
||||
Source AnthroveSource `json:"source"`
|
||||
}
|
||||
type AnthrovePostRelationship struct {
|
||||
PostID string `json:"post_id"`
|
||||
Url string `json:"url"`
|
||||
PostID string `json:"post_id" format:"string"`
|
||||
Url string `json:"url" format:"string"`
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
type AnthroveSource struct {
|
||||
DisplayName string `json:"display_name"`
|
||||
Domain string `json:"domain"`
|
||||
Icon string `json:"icon"`
|
||||
DisplayName AnthroveSourceDisplayName `json:"display_name" format:"string"`
|
||||
Domain AnthroveSourceDomain `json:"domain" format:"string"`
|
||||
Icon AnthroveSourceIcon `json:"icon" format:"string"`
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
package models
|
||||
|
||||
type AnthroveTag struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name" format:"string"`
|
||||
Type string `json:"type" format:"string"`
|
||||
}
|
||||
|
||||
type TagsWithFrequency struct {
|
||||
Frequency int64 `json:"frequency"`
|
||||
Tags AnthroveTag `json:"tags"`
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
type AnthroveUser struct {
|
||||
UserID AnthroveUserID `json:"user_id"`
|
||||
UserID AnthroveUserID `json:"user_id" format:"string"`
|
||||
Relationship []AnthroveUserRelationship `json:"relationship"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user