feat(post): added deletion of posts & added some documentation for the add function as well
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
6cabcf9beb
commit
6760948e73
@ -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,6 +32,29 @@ func CreateAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext,
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, driver neo4j.DriverWithContext, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
|
||||
query := `
|
||||
OPTIONAL MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
||||
|
@ -2,12 +2,13 @@ package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||
)
|
||||
|
||||
type Post interface {
|
||||
CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
||||
DeletePost() error
|
||||
DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) error
|
||||
|
||||
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
|
||||
// It returns an error if the operation fails.
|
||||
|
@ -2,17 +2,20 @@ package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.dragse.it/anthrove/otter-space-sdk/internal"
|
||||
"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 internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||
}
|
||||
|
||||
func (g *graphConnection) DeletePost() error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
// 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 internal.DeleteAnthrovePostNode(ctx, g.driver, anthrovePost)
|
||||
|
||||
}
|
||||
|
||||
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
|
||||
|
Reference in New Issue
Block a user