feat: implemented user post relationship check
This commit is contained in:
parent
1919cf5c76
commit
c9f88ffb5d
@ -2,6 +2,7 @@ package internal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/anthrove-graph-sdk.git/pkg/models"
|
"git.dragse.it/anthrove/anthrove-graph-sdk.git/pkg/models"
|
||||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
||||||
@ -62,3 +63,38 @@ func EstablishUserToPostLink(ctx context.Context, driver neo4j.DriverWithContext
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckUserToPostLink(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourcePostID string, sourcePostUrl string) (bool, error) {
|
||||||
|
query := `
|
||||||
|
OPTIONAL MATCH (:User {user_id: $anthrove_user_id})-[f:FAV]->(:AnthrovePost)<-[:REFERENCE{source_post_id: $source_post_id}]-(:Source{domain: $source_domain})
|
||||||
|
RETURN COUNT(f) > 0 AS hasRelationship
|
||||||
|
`
|
||||||
|
|
||||||
|
params := map[string]any{
|
||||||
|
"anthrove_user_id": anthroveUserID,
|
||||||
|
"source_post_id": sourcePostID,
|
||||||
|
"source_domain": sourcePostUrl,
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result.Records) == 0 {
|
||||||
|
return false, fmt.Errorf("no records found")
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, _, err := neo4j.GetRecordValue[bool](result.Records[0], "hasRelationship")
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"relationship_exists": exists,
|
||||||
|
"relationship_anthrove_user_id": anthroveUserID,
|
||||||
|
"relationship_e621_post_id": "",
|
||||||
|
}).Trace("graph: checked user post relationship")
|
||||||
|
|
||||||
|
return exists, nil
|
||||||
|
}
|
||||||
|
@ -28,8 +28,8 @@ type Graph interface {
|
|||||||
// LinkUserWithPost establishes a link between a user and a post in the graph
|
// LinkUserWithPost establishes a link between a user and a post in the graph
|
||||||
LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error
|
LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error
|
||||||
|
|
||||||
// VerifyUserPostLink checks if a link between a user and a post exists in the graph
|
// CheckUserPostLink checks if a link between a user and a post exists in the graph
|
||||||
VerifyUserPostLink(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveUser *models.AnthroveUser) (bool, error)
|
CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourcePostUrl string) (bool, error)
|
||||||
|
|
||||||
// CheckPostNodeExistsByAnthroveID checks if an Anthrove post node exists in the graph by its Anthrove ID
|
// CheckPostNodeExistsByAnthroveID checks if an Anthrove post node exists in the graph by its Anthrove ID
|
||||||
CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (bool, error)
|
CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (bool, error)
|
||||||
|
@ -60,9 +60,8 @@ func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *mo
|
|||||||
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
|
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) VerifyUserPostLink(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveUser *models.AnthroveUser) (bool, error) {
|
func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourcePostUrl string) (bool, error) {
|
||||||
//TODO implement me
|
return internal.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourcePostUrl)
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (bool, error) {
|
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (bool, error) {
|
||||||
|
Reference in New Issue
Block a user