in lambda/src/main/scala/pricemigrationengine/model/dynamodb/Conversions.scala [16:44]
def stringFieldUpdate(fieldName: String, stringValue: String): (String, AttributeValueUpdate) =
fieldName -> AttributeValueUpdate.builder.value(AttributeValue.builder.s(stringValue).build()).action(PUT).build()
def dateFieldUpdate(fieldName: String, dateValue: LocalDate): (String, AttributeValueUpdate) =
fieldName -> AttributeValueUpdate.builder
.value(AttributeValue.builder.s(dateValue.format(ISO_LOCAL_DATE)).build())
.action(PUT)
.build()
def instantFieldUpdate(fieldName: String, instant: Instant): (String, AttributeValueUpdate) =
fieldName -> AttributeValueUpdate.builder
.value(AttributeValue.builder.s(ISO_DATE_TIME.format(instant.atZone(UTC))).build())
.action(PUT)
.build()
def bigDecimalFieldUpdate(fieldName: String, value: BigDecimal): (String, AttributeValueUpdate) =
fieldName -> AttributeValueUpdate.builder
.value(AttributeValue.builder.n(value.toString).build())
.action(PUT)
.build()
def stringUpdate(fieldName: String, stringValue: String): (String, AttributeValue) =
fieldName -> AttributeValue.builder.s(stringValue).build()
def getStringFromResults(result: util.Map[String, AttributeValue], fieldName: String): Either[String, String] =
for {
optionalString <- getOptionalStringFromResults(result, fieldName)
string <- optionalString.toRight(s"The '$fieldName' field did not exist in the record '$result''")
} yield string