2023-06-20 08:38:36 +00:00
|
|
|
package neo4j
|
2023-05-22 20:10:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
|
|
|
)
|
|
|
|
|
2023-06-20 08:38:36 +00:00
|
|
|
func EstablishPostTagLink(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, e621Tag string) error {
|
2023-05-22 20:10:05 +00:00
|
|
|
query := `
|
|
|
|
MATCH (p:e621Post {e621PostID: $e621PostID})
|
|
|
|
MATCH (t:e621Tag {e621Tag: $e621Tag})
|
|
|
|
MERGE (p)-[:HAS_TAG]->(t)
|
|
|
|
`
|
|
|
|
params := map[string]interface{}{
|
|
|
|
"e621PostID": e621PostID,
|
|
|
|
"e621Tag": e621Tag,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-20 08:38:36 +00:00
|
|
|
func EstablishPostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, sourceURL string) error {
|
2023-05-22 20:10:05 +00:00
|
|
|
query := `
|
|
|
|
MATCH (p:e621Post {e621PostID: $e621PostID})
|
|
|
|
MATCH (s:Source {URL: $sourceURL})
|
|
|
|
MERGE (p)-[:HAS_SOURCE]->(s)
|
|
|
|
`
|
|
|
|
params := map[string]interface{}{
|
|
|
|
"e621PostID": e621PostID,
|
|
|
|
"sourceURL": sourceURL,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-20 08:38:36 +00:00
|
|
|
func EstablishUserToPostLink(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, e621UserID int64) error {
|
2023-05-22 20:10:05 +00:00
|
|
|
query := `
|
|
|
|
MATCH (p:e621Post {e621PostID: $e621PostID})
|
|
|
|
MATCH (u:e621User {e621ID: $e621ID})
|
|
|
|
MERGE (u)-[:IS_FAVORITE]->(p)
|
|
|
|
`
|
|
|
|
params := map[string]interface{}{
|
|
|
|
"e621PostID": e621PostID,
|
|
|
|
"e621ID": e621UserID,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2023-05-30 12:04:13 +00:00
|
|
|
|
|
|
|
// CheckUserToPostRelationship gives back a bool if the connection between the post and the user exists
|
2023-06-20 08:38:36 +00:00
|
|
|
func RelationshipCheckUserToPost(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, e621UserID int64) (bool, error) {
|
2023-05-30 12:04:13 +00:00
|
|
|
query := `
|
2023-06-17 17:13:25 +00:00
|
|
|
MATCH (user:e621User {e621ID: $e621ID})-[favorite:IS_FAVORITE]->(post:e621Post {e621PostID: $e621PostID})
|
2023-05-30 12:04:13 +00:00
|
|
|
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 {
|
2023-06-17 17:13:25 +00:00
|
|
|
return false, err
|
2023-05-30 12:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exists, _, err := neo4j.GetRecordValue[bool](result.Records[0], "isFavorite")
|
|
|
|
if err != nil {
|
2023-06-17 17:13:25 +00:00
|
|
|
return false, err
|
2023-05-30 12:04:13 +00:00
|
|
|
}
|
2023-06-17 17:13:25 +00:00
|
|
|
return exists, nil
|
2023-05-30 12:04:13 +00:00
|
|
|
}
|