Compare commits
No commits in common. "4cb887701b0532990274615252e654ec1e0e6249" and "2c43149c9efdedacaebc11701d3741000768ca0c" have entirely different histories.
4cb887701b
...
2c43149c9e
@ -33,43 +33,3 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]models.AnthroveSource, error) {
|
|
||||||
var sources []models.AnthroveSource
|
|
||||||
|
|
||||||
query := `
|
|
||||||
MATCH (s:Source)
|
|
||||||
RETURN s as source
|
|
||||||
`
|
|
||||||
params := map[string]any{}
|
|
||||||
|
|
||||||
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(result.Records) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range result.Records {
|
|
||||||
record := result.Records[i]
|
|
||||||
|
|
||||||
source, _, err := neo4j.GetRecordValue[neo4j.Node](record, "source")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sources = append(sources, models.AnthroveSource{
|
|
||||||
DisplayName: source.Props["display_name"].(string),
|
|
||||||
Domain: source.Props["domain"].(string),
|
|
||||||
Icon: source.Props["icon"].(string),
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"tag_amount": len(sources),
|
|
||||||
}).Trace("graph: created tag node")
|
|
||||||
|
|
||||||
return sources, nil
|
|
||||||
}
|
|
||||||
|
@ -33,52 +33,3 @@ func CreateTagNodeWitRelation(ctx context.Context, driver neo4j.DriverWithContex
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTags(ctx context.Context, driver neo4j.DriverWithContext) ([]models.TagsWithFrequency, error) {
|
|
||||||
var userTags []models.TagsWithFrequency
|
|
||||||
|
|
||||||
query := `
|
|
||||||
MATCH (:AnthrovePost)-[:HAS]->(t:Tag)
|
|
||||||
RETURN t as tag, COUNT(t) AS frequency
|
|
||||||
ORDER BY frequency DESC
|
|
||||||
`
|
|
||||||
params := map[string]any{}
|
|
||||||
|
|
||||||
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(result.Records) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range result.Records {
|
|
||||||
record := result.Records[i]
|
|
||||||
|
|
||||||
tag, _, err := neo4j.GetRecordValue[neo4j.Node](record, "tag")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
frequency, _, err := neo4j.GetRecordValue[int64](record, "frequency")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
userTags = append(userTags, models.TagsWithFrequency{
|
|
||||||
Frequency: frequency,
|
|
||||||
Tags: models.AnthroveTag{
|
|
||||||
Name: tag.Props["name"].(string),
|
|
||||||
Type: tag.Props["type"].(string),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"tag_amount": len(userTags),
|
|
||||||
}).Trace("graph: created tag node")
|
|
||||||
|
|
||||||
return userTags, nil
|
|
||||||
}
|
|
||||||
|
@ -295,6 +295,7 @@ func GetAllAnthroveUserIDs(ctx context.Context, driver neo4j.DriverWithContext)
|
|||||||
if len(result.Records) == 0 {
|
if len(result.Records) == 0 {
|
||||||
log.Warnf("No users found, this should not be happening!")
|
log.Warnf("No users found, this should not be happening!")
|
||||||
return []models.AnthroveUserID{}, nil
|
return []models.AnthroveUserID{}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range result.Records {
|
for i := range result.Records {
|
||||||
@ -401,54 +402,3 @@ func GetUserFavoriteNodeWithPagination(ctx context.Context, driver neo4j.DriverW
|
|||||||
return &models.FavoriteList{Posts: favoritePosts}, nil
|
return &models.FavoriteList{Posts: favoritePosts}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserTagNodeWitRelationToFavedPosts(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
|
|
||||||
var userTags []models.TagsWithFrequency
|
|
||||||
|
|
||||||
query := `
|
|
||||||
MATCH (u:User {user_id: $anthrove_user_id})-[:FAV]->(:AnthrovePost)-[:HAS]->(t:Tag)
|
|
||||||
RETURN t as tag, COUNT(t) AS frequency
|
|
||||||
ORDER BY frequency DESC
|
|
||||||
`
|
|
||||||
params := map[string]any{
|
|
||||||
"anthrove_user_id": anthroveUserID,
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(result.Records) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range result.Records {
|
|
||||||
record := result.Records[i]
|
|
||||||
|
|
||||||
tag, _, err := neo4j.GetRecordValue[neo4j.Node](record, "tag")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
frequency, _, err := neo4j.GetRecordValue[int64](record, "frequency")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
userTags = append(userTags, models.TagsWithFrequency{
|
|
||||||
Frequency: frequency,
|
|
||||||
Tags: models.AnthroveTag{
|
|
||||||
Name: tag.Props["name"].(string),
|
|
||||||
Type: tag.Props["type"].(string),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"tag_amount": len(userTags),
|
|
||||||
}).Trace("graph: created tag node")
|
|
||||||
|
|
||||||
return userTags, nil
|
|
||||||
}
|
|
||||||
|
@ -101,13 +101,4 @@ type OtterSpace interface {
|
|||||||
|
|
||||||
// GetUserFavoritePostsWithPagination gets all user favorites with relation and sources for the given user
|
// GetUserFavoritePostsWithPagination gets all user favorites with relation and sources for the given user
|
||||||
GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error)
|
GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error)
|
||||||
|
|
||||||
// GetUserTagsTroughFavedPosts returns a list of Tags that the user hs favorites through a post
|
|
||||||
GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error)
|
|
||||||
|
|
||||||
// GetAllTags returns a list of Tags that the user hs favorites through a post
|
|
||||||
GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error)
|
|
||||||
|
|
||||||
// GetAllSources returns a list of Sources in the database
|
|
||||||
GetAllSources(ctx context.Context) ([]models.AnthroveSource, error)
|
|
||||||
}
|
}
|
||||||
|
@ -100,18 +100,6 @@ func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context
|
|||||||
return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
|
return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
|
|
||||||
return internal.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) {
|
|
||||||
return internal.GetTags(ctx, g.driver)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
|
|
||||||
return internal.GetAllSourceNodes(ctx, g.driver)
|
|
||||||
}
|
|
||||||
|
|
||||||
func logger(graphDebug bool) func(config *config.Config) {
|
func logger(graphDebug bool) func(config *config.Config) {
|
||||||
return func(config *config.Config) {
|
return func(config *config.Config) {
|
||||||
config.Log = internal.NewGraphLogger(graphDebug)
|
config.Log = internal.NewGraphLogger(graphDebug)
|
||||||
|
@ -13,8 +13,3 @@ type FavoritePost struct {
|
|||||||
type FavoriteList struct {
|
type FavoriteList struct {
|
||||||
Posts []FavoritePost `json:"posts,omitempty"`
|
Posts []FavoritePost `json:"posts,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagsWithFrequency struct {
|
|
||||||
Frequency int64 `json:"frequency"`
|
|
||||||
Tags AnthroveTag `json:"tags"`
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user