Compare commits
No commits in common. "05864e2fcb94eafe731a563dfcb869f262f27994" and "175fb4daab061839a002e7a8cbdb0a6e77c0c771" have entirely different histories.
05864e2fcb
...
175fb4daab
@ -149,67 +149,6 @@ func GetUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anth
|
|||||||
return userSource, nil
|
return userSource, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
|
|
||||||
|
|
||||||
userSource := make(map[string]models.AnthroveUserRelationship)
|
|
||||||
|
|
||||||
query := `
|
|
||||||
MATCH (user:User{user_id: $anthrove_user_id})-[r:HAS_ACCOUNT_AT]->(s:Source{display_name: $source_display_name})
|
|
||||||
RETURN toString(r.user_id) AS sourceUserID, toString(r.username) AS sourceUsername, s as source;
|
|
||||||
`
|
|
||||||
params := map[string]any{
|
|
||||||
"anthrove_user_id": anthroveUserID,
|
|
||||||
"source_display_name": sourceDisplayName,
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(result.Records) == 0 {
|
|
||||||
return nil, fmt.Errorf("user has no relations with the source %s", sourceDisplayName)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range result.Records {
|
|
||||||
record := result.Records[i]
|
|
||||||
source, _, err := neo4j.GetRecordValue[neo4j.Node](record, "source")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sourceUserID, _, err := neo4j.GetRecordValue[string](record, "sourceUserID")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sourceUsername, _, err := neo4j.GetRecordValue[string](record, "sourceUsername")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
displayName := source.Props["display_name"].(string)
|
|
||||||
domain := source.Props["domain"].(string)
|
|
||||||
icon := source.Props["icon"].(string)
|
|
||||||
|
|
||||||
anthroveSourceUser := models.AnthroveUserRelationship{
|
|
||||||
UserID: sourceUserID,
|
|
||||||
Username: sourceUsername,
|
|
||||||
Source: models.AnthroveSource{
|
|
||||||
DisplayName: displayName,
|
|
||||||
Domain: domain,
|
|
||||||
Icon: icon,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
userSource[displayName] = anthroveSourceUser
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"anthrove_user_id": anthroveUserID,
|
|
||||||
"anthrove_data": userSource,
|
|
||||||
}).Trace("graph: got user favorite count")
|
|
||||||
|
|
||||||
return userSource, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
|
func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
|
||||||
var err error
|
var err error
|
||||||
var anthroveUser models.AnthroveUser
|
var anthroveUser models.AnthroveUser
|
||||||
|
@ -86,10 +86,6 @@ type OtterSpace interface {
|
|||||||
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
|
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
|
||||||
GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error)
|
GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error)
|
||||||
|
|
||||||
// GetUserSourceLinks retrieves the links between a user and sources in the OtterSpace graph.
|
|
||||||
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
|
|
||||||
GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error)
|
|
||||||
|
|
||||||
// GetAnthroveUser retrieves a user from the OtterSpace graph by their ID.
|
// GetAnthroveUser retrieves a user from the OtterSpace graph by their ID.
|
||||||
// It returns the user and an error if the operation fails.
|
// It returns the user and an error if the operation fails.
|
||||||
GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error)
|
GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error)
|
||||||
|
@ -84,10 +84,6 @@ func (g *graphConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID
|
|||||||
return internal.GetUserSourceLink(ctx, g.driver, anthroveUserID)
|
return internal.GetUserSourceLink(ctx, g.driver, anthroveUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
|
|
||||||
return internal.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
|
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
|
||||||
return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID)
|
return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user