public async Task <IEnumerable <PhotoModel> > GetLatestPhotos(UserId currentUserId) { logWriter.LogInformation($"{nameof(GetLatestPhotos)}()"); var request = new QueryRequest { TableName = tableName, IndexName = "GSI2", KeyConditionExpression = $"{FieldMappings.RecordType} = :recordType", FilterExpression = $"{FieldMappings.Photo.State} = :state", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":recordType", new AttributeValue { S = "photo" } }, { ":state", new AttributeValue { S = PhotoState.PhotoAvailable.ToString() } }, }, ScanIndexForward = false, // order descending Limit = 250, ReturnConsumedCapacity = ReturnConsumedCapacity.INDEXES }; var response = (await dynamoDbCore.Query(request, Mappers.PhotoModel)); var result = new ConcurrentDictionary <PhotoId, PhotoModel>(); foreach (var photo in response) { result.TryAdd(photo.PhotoId, photo); } await AddLikeDataForUser(currentUserId, result); return(result.Values.OrderByDescending(x => x.CreatedTime)); }
public async Task <UserModel> GetUserById(UserId userId) { var request = new QueryRequest(tableName); request.IndexName = "GSI1"; request.KeyConditions = new Dictionary <string, Condition> { { "SortKey", dynamoDbCore.GetStringEqualsCondition("user") }, { "GSI1PartitionKey", dynamoDbCore.GetStringEqualsCondition(userId.ToDbValue()) } }; return((await dynamoDbCore.Query(request, Mappers.UserModel)).FirstOrDefault() ?? UserModel.Null); }
public Task <IEnumerable <PhotoComment> > GetComments(PhotoId photoId) { logWriter.LogInformation($"{nameof(GetComments)}({nameof(photoId)} = '{photoId}')"); QueryRequest request = new QueryRequest { TableName = tableName, KeyConditions = new Dictionary <string, Condition> { { FieldMappings.PartitionKey, dynamoDbCore.GetStringEqualsCondition(photoId.ToDbValue()) }, { FieldMappings.SortKey, dynamoDbCore.GetStringBeginsWithCondition("comment") } } }; return(dynamoDbCore.Query(request, Mappers.PhotoComment)); }