added check function for user to post relationship
This commit is contained in:
parent
7d494d5f7a
commit
0e07b02346
@ -61,3 +61,26 @@ func UserToPostRelationship(ctx context.Context, driver neo4j.DriverWithContext,
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckUserToPostRelationship gives back a bool if the connection between the post and the user exists
|
||||||
|
func CheckUserToPostRelationship(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, e621UserID int64) (error, bool) {
|
||||||
|
query := `
|
||||||
|
MATCH (user:e621User {e621ID: $e621PostID})-[favorite:IS_FAVORITE]->(post:e621Post {e621PostID: $e621ID})
|
||||||
|
RETURN COUNT(favorite) > 0 AS isFavorite
|
||||||
|
`
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"e621PostID": e621PostID,
|
||||||
|
"e621ID": e621UserID,
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
||||||
|
if err != nil {
|
||||||
|
return err, false
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, _, err := neo4j.GetRecordValue[bool](result.Records[0], "isFavorite")
|
||||||
|
if err != nil {
|
||||||
|
return err, false
|
||||||
|
}
|
||||||
|
return nil, exists
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user