Skip to content

Instantly share code, notes, and snippets.

@RyPope
Last active February 5, 2019 05:24
Show Gist options
  • Save RyPope/d821cf3c442542cc7f7c9af9e423823c to your computer and use it in GitHub Desktop.
Save RyPope/d821cf3c442542cc7f7c9af9e423823c to your computer and use it in GitHub Desktop.
public class GetFeedHandler implements RequestHandler<GetFeedRequest, GetFeedResponse> {
@Inject LambdaLogger mLambdaLogger;
@Inject @Named(TableConstants.FEED_USERID_CREATED_AT_INDEX) Index mSortedFeedIndex;
@Inject @Named(QueryConstants.FEED_SORTED_QUERY) QuerySpec mSortedFeedQuery;
public GetFeedResponse handleRequest(final GetFeedRequest input, final Context context) {
Injector.getInjector(context).inject(this);
final List<String> activityIds = getActivitiesForUser(input.getUserId());
return new GetFeedResponse(activityIds);
}
private List<String> getActivitiesForUser(final String userId) {
mLambdaLogger.log(String.format("Querying activities for user %s", userId));
final ItemCollection<QueryOutcome> items = mSortedFeedIndex.query(buildQueryForUserId(userId));
return extractUserIds(items);
}
private QuerySpec buildQueryForUserId(final String userId) {
return mSortedFeedQuery
.withValueMap(new ValueMap().withString(":userId", userId));
}
private List<String> extractUserIds(final ItemCollection<QueryOutcome> items) {
final List<String> activityIds = new ArrayList<>();
for (final Item activity : items) {
final String activityId = (String) activity.get(TableConstants.FEED_ID_COLUMN);
mLambdaLogger.log(String.format("Found activity %s", activityId));
activityIds.add(activityId);
}
return activityIds;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment