Skip to content

Instantly share code, notes, and snippets.

@HenryQW
Created November 20, 2023 23:57
Show Gist options
  • Save HenryQW/9d960fcd42bfd6b701f419c89da63d4a to your computer and use it in GitHub Desktop.
Save HenryQW/9d960fcd42bfd6b701f419c89da63d4a to your computer and use it in GitHub Desktop.
client_activity.go
func (c *client) FindActivities(ctx context.Context, query model.ActivitiesQuery) ([]*model.Activity, error) {
indexesQuery := model.IndexesQuery{
Distinct: query.Distinct,
Owner: query.Owner,
Limit: query.Limit,
Cursor: query.Cursor,
Status: query.Status,
Direction: query.Direction,
StartTimestamp: query.StartTimestamp,
EndTimestamp: query.EndTimestamp,
Platform: query.Platform,
Owners: query.Owners,
Chains: query.Chains,
Platforms: query.Platforms,
Tags: query.Tags,
Types: query.Types,
}
indexes, err := c.FindIndexes(ctx, indexesQuery)
if err != nil {
return nil, err
}
feedsQuery := lo.SliceToMap(indexes, func(index *model.Index) (string, model.FeedQuery) {
return index.ID, model.FeedQuery{
ID: index.ID,
Chain: index.Chain,
Timestamp: index.Timestamp,
}
})
feeds, err := c.FindFeeds(ctx, lo.MapToSlice(feedsQuery, func(_ string, feedQuery model.FeedQuery) model.FeedQuery {
return feedQuery
}))
if err != nil {
return nil, err
}
lo.ForEach(feeds, func(feed *model.Feed, i int) {
feeds[i].Actions = lo.Slice(feed.Actions, 0, query.ActionLimit)
})
return model.TransformActivities(indexes, feeds), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment