Skip to content

Instantly share code, notes, and snippets.

@RyPope
Last active February 5, 2019 05:24
Show Gist options
  • Save RyPope/855ba1dee0303141abbe9c0626a37ad2 to your computer and use it in GitHub Desktop.
Save RyPope/855ba1dee0303141abbe9c0626a37ad2 to your computer and use it in GitHub Desktop.
public class GetFeedHandler implements RequestHandler<GetFeedRequest, GetFeedResponse> {
@Inject DynamoDB mDynamoDB;
@Inject LambdaLogger mLambdaLogger;
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) {
final List<String> activityIds = new ArrayList<>();
mLambdaLogger.log(String.format("Querying activities for user %s", userId));
final Table table = mDynamoDB.getTable(TableConstants.FEED_TABLE_NAME);
final Index index = table.getIndex(TableConstants.FEED_USERID_CREATED_AT_INDEX);
final QuerySpec spec = new QuerySpec()
.withKeyConditionExpression("#U = :userId")
.withValueMap(new ValueMap()
.withString(":userId", userId))
.withNameMap(new NameMap()
.with("#U", TableConstants.FEED_USERID_COLUMN))
.withScanIndexForward(false);
final ItemCollection<QueryOutcome> items = index.query(spec);
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