Merge pull request 'feat: added GetSpecifiedUserSourceLink fucntion' (#2) from more-querys into main
Reviewed-on: #2
This commit is contained in:
commit
05864e2fcb
@ -149,6 +149,67 @@ func GetUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anth
|
||||
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) {
|
||||
var err error
|
||||
var anthroveUser models.AnthroveUser
|
||||
|
@ -86,6 +86,10 @@ type OtterSpace interface {
|
||||
// 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 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.
|
||||
// It returns the user and an error if the operation fails.
|
||||
GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error)
|
||||
|
@ -84,6 +84,10 @@ func (g *graphConnection) GetUserSourceLinks(ctx context.Context, 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) {
|
||||
return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID)
|
||||
}
|
||||
|
Reference in New Issue
Block a user