Stop writing non tag-set field

This commit is contained in:
Ravi Khadiwala 2024-12-10 11:38:56 -06:00 committed by ravi-signal
parent 18c9b177f3
commit e1e94a33e2
2 changed files with 2 additions and 7 deletions

View File

@ -40,7 +40,6 @@ import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest;
public class IssuedReceiptsManager { public class IssuedReceiptsManager {
public static final String KEY_PROCESSOR_ITEM_ID = "A"; // S (HashKey) public static final String KEY_PROCESSOR_ITEM_ID = "A"; // S (HashKey)
public static final String KEY_ISSUED_RECEIPT_TAG = "B"; // B
public static final String KEY_EXPIRATION = "E"; // N public static final String KEY_EXPIRATION = "E"; // N
public static final String KEY_ISSUED_RECEIPT_TAG_SET = "T"; // BS public static final String KEY_ISSUED_RECEIPT_TAG_SET = "T"; // BS
@ -86,13 +85,9 @@ public class IssuedReceiptsManager {
.key(Map.of(KEY_PROCESSOR_ITEM_ID, key)) .key(Map.of(KEY_PROCESSOR_ITEM_ID, key))
.conditionExpression("attribute_not_exists(#key) OR contains(#tags, :tag) OR size(#tags) < :maxTags") .conditionExpression("attribute_not_exists(#key) OR contains(#tags, :tag) OR size(#tags) < :maxTags")
.returnValues(ReturnValue.NONE) .returnValues(ReturnValue.NONE)
.updateExpression("SET " .updateExpression("SET #exp = if_not_exists(#exp, :exp) ADD #tags :singletonTag")
+ "#tag = if_not_exists(#tag, :tag), "
+ "#exp = if_not_exists(#exp, :exp) "
+ "ADD #tags :singletonTag")
.expressionAttributeNames(Map.of( .expressionAttributeNames(Map.of(
"#key", KEY_PROCESSOR_ITEM_ID, "#key", KEY_PROCESSOR_ITEM_ID,
"#tag", KEY_ISSUED_RECEIPT_TAG,
"#tags", KEY_ISSUED_RECEIPT_TAG_SET, "#tags", KEY_ISSUED_RECEIPT_TAG_SET,
"#exp", KEY_EXPIRATION)) "#exp", KEY_EXPIRATION))
.expressionAttributeValues(Map.of( .expressionAttributeValues(Map.of(

View File

@ -73,7 +73,7 @@ class IssuedReceiptsManagerTest {
.stream() .stream()
.map(SdkBytes::asByteArray) .map(SdkBytes::asByteArray)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
assertThat(tagSet).containsExactly(item.get(IssuedReceiptsManager.KEY_ISSUED_RECEIPT_TAG).b().asByteArray()); assertThat(tagSet).containsExactly(issuedReceiptsManager.generateIssuedReceiptTag(receiptCredentialRequest));
// same request should succeed // same request should succeed
future = issuedReceiptsManager.recordIssuance("item-1", PaymentProvider.STRIPE, receiptCredentialRequest, future = issuedReceiptsManager.recordIssuance("item-1", PaymentProvider.STRIPE, receiptCredentialRequest,