56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.dragse.it/anthrove/anthrove-graph-sdk.git/pkg/models"
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func CreateUserNodeWithSourceRelation(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) (*models.AnthroveUser, 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)
|
|
`
|
|
params := map[string]any{
|
|
"anthrove_user_id": anthroveUserID,
|
|
"source_user_id": userID,
|
|
"source_user_name": username,
|
|
"source_domain": sourceDomain,
|
|
}
|
|
|
|
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var anthroveUserRelationship []models.AnthroveUserRelationship
|
|
|
|
anthroveUserRelationship = append(anthroveUserRelationship, models.AnthroveUserRelationship{
|
|
UserID: userID,
|
|
Username: username,
|
|
ScrapeTimeInterval: "",
|
|
Source: models.AnthroveSource{
|
|
DisplayName: "",
|
|
Domain: sourceDomain,
|
|
Icon: "",
|
|
},
|
|
})
|
|
|
|
anthroveUser := models.AnthroveUser{
|
|
UserID: anthroveUserID,
|
|
Relationship: anthroveUserRelationship,
|
|
}
|
|
|
|
log.WithFields(log.Fields{
|
|
"anthrove_user_id": anthroveUserID,
|
|
"source_user_id": userID,
|
|
"source_user_name": username,
|
|
"source_domain": sourceDomain,
|
|
}).Trace("graph: crated user with relationship")
|
|
|
|
return &anthroveUser, nil
|
|
}
|