feat: added GetUserFavoritePostsWithPagination function
This commit is contained in:
parent
f54d7244c5
commit
302b4b5f9c
@ -315,3 +315,52 @@ func GetAllAnthroveUserIDs(ctx context.Context, driver neo4j.DriverWithContext)
|
|||||||
return anthroveUsers, nil
|
return anthroveUsers, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserFavoriteNodeWithPagination(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, skip int, limit int) ([]models.AnthrovePost, error) {
|
||||||
|
var err error
|
||||||
|
var anthrovePosts []models.AnthrovePost
|
||||||
|
|
||||||
|
query := `
|
||||||
|
MATCH (user:User{user_id: $anthrove_user_id})-[r:FAV]->(p:AnthrovePost)
|
||||||
|
RETURN p as anthrovePost
|
||||||
|
ORDER BY id(r) DESC
|
||||||
|
SKIP $skip
|
||||||
|
LIMIT $limit;
|
||||||
|
`
|
||||||
|
params := map[string]any{
|
||||||
|
"anthrove_user_id": anthroveUserID,
|
||||||
|
"limit": limit,
|
||||||
|
"skip": skip,
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
post, _, err := neo4j.GetRecordValue[neo4j.Node](record, "anthrovePost")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
anthrovePosts = append(anthrovePosts, models.AnthrovePost{
|
||||||
|
PostID: models.AnthrovePostID(post.Props["post_id"].(string)),
|
||||||
|
Rating: models.AnthroveRating(post.Props["rating"].(string)),
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"anthrove_user_fav_count": len(anthrovePosts),
|
||||||
|
}).Trace("graph: got al anthrove user favorites")
|
||||||
|
|
||||||
|
return anthrovePosts, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -97,4 +97,7 @@ type OtterSpace interface {
|
|||||||
// GetAllAnthroveUserIDs retrieves all user IDs from the OtterSpace graph.
|
// GetAllAnthroveUserIDs retrieves all user IDs from the OtterSpace graph.
|
||||||
// It returns a slice of user IDs and an error if the operation fails.
|
// It returns a slice of user IDs and an error if the operation fails.
|
||||||
GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error)
|
GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error)
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) ([]models.AnthrovePost, error)
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,10 @@ func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.A
|
|||||||
return internal.GetAllAnthroveUserIDs(ctx, g.driver)
|
return internal.GetAllAnthroveUserIDs(ctx, g.driver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) ([]models.AnthrovePost, error) {
|
||||||
|
return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
Reference in New Issue
Block a user