diff --git a/src/main/java/com/yuriytkach/tracker/fundraiser/service/dynamodb/DynamoDbDonationClientDonation.java b/src/main/java/com/yuriytkach/tracker/fundraiser/service/dynamodb/DynamoDbDonationClientDonation.java index c6b3889..9b22930 100644 --- a/src/main/java/com/yuriytkach/tracker/fundraiser/service/dynamodb/DynamoDbDonationClientDonation.java +++ b/src/main/java/com/yuriytkach/tracker/fundraiser/service/dynamodb/DynamoDbDonationClientDonation.java @@ -22,7 +22,7 @@ import software.amazon.awssdk.services.dynamodb.model.PutRequest; import software.amazon.awssdk.services.dynamodb.model.ScanRequest; import software.amazon.awssdk.services.dynamodb.model.WriteRequest; -import software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException; + @Slf4j @Singleton @@ -67,8 +67,7 @@ public void addAll(final String fundId, final Collection donations) { .map(putRequest -> WriteRequest.builder().putRequest(putRequest).build()) .toImmutableSet(); - final String conditionExpression = "attribute_not_exists(" + COL_CURR + ") OR " + COL_AMOUNT + " = :value"; - final Map expressionAttributeValues = Map.of(":value", AttributeValue.builder().n(String.valueOf(currentFundTotal)).build()); + final BatchWriteItemRequest request = BatchWriteItemRequest.builder() .requestItems(Map.of(fundId, writeRequests)) @@ -76,12 +75,8 @@ public void addAll(final String fundId, final Collection donations) { .expressionAttributeValues(expressionAttributeValues) .build(); BatchWriteItemResponse response; - try { - response = dynamoDB.batchWriteItem(request); - log.debug("Saved donations. Consumed capacity: {}", response.consumedCapacity()); - } catch (ConditionalCheckFailedException e) { - throw new FundTotalMismatchException("Failed to save donations due to a mismatch in fund total.", e); - } + final BatchWriteItemResponse response = dynamoDB.batchWriteItem(request); + log.debug("Saved donations. Consumed capacity: {}", response.consumedCapacity()); } @Override