Created
May 25, 2020 13:47
-
-
Save bijukunjummen/d7c796d4ad0e0d33bbf70c9306a96946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http :9080/hotels id=4 name=name address=address zip=zip state=OR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"address": "address", | |
"id": "4", | |
"name": "name", | |
"state": "OR", | |
"version": 1, | |
"zip": "zip" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http PUT :9080/hotels/4 name=name1 address=address zip=zip state=OR version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"address": "address", | |
"id": "4", | |
"name": "name1", | |
"state": "OR", | |
"version": 2, | |
"zip": "zip" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"TableName": "hotels", | |
"Key": { | |
"id": { | |
"S": "1" | |
} | |
}, | |
"UpdateExpression": "\nSET #name=:name,\n #state=:state,\naddress=:address,\nzip=:zip\nADD version :inc\n ", | |
"ExpressionAttributeNames": { | |
"#state": "state", | |
"#name": "name" | |
}, | |
"ExpressionAttributeValues": { | |
":name": { | |
"S": "testhotel" | |
}, | |
":address": { | |
"S": "testaddress" | |
}, | |
":state": { | |
"S": "OR" | |
}, | |
":zip": { | |
"S": "zip" | |
}, | |
":inc": { | |
"N": "1" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val updateItemRequest = UpdateItemRequest.builder() | |
.tableName(TABLE_NAME) | |
.key( | |
mapOf( | |
ID to AttributeValue.builder().s(hotel.id).build() | |
) | |
) | |
.updateExpression( | |
""" | |
SET #name=:name, | |
#state=:state, | |
address=:address, | |
zip=:zip | |
ADD version :inc | |
""" | |
) | |
.conditionExpression("version = :version") | |
.expressionAttributeValues( | |
mapOf( | |
":${NAME}" to AttributeValue.builder().s(hotel.name).build(), | |
":${ZIP}" to AttributeValue.builder().s(hotel.zip).build(), | |
":${STATE}" to AttributeValue.builder().s(hotel.state).build(), | |
":${ADDRESS}" to AttributeValue.builder().s(hotel.address).build(), | |
":${VERSION}" to AttributeValue.builder().n(hotel.version.toString()).build(), | |
":inc" to AttributeValue.builder().n("1").build() | |
) | |
) | |
.expressionAttributeNames( | |
mapOf( | |
"#name" to "name", | |
"#state" to "state" | |
) | |
) | |
.build() | |
val updateItem: CompletableFuture<UpdateItemResponse> = dynamoClient.updateItem(updateItemRequest) | |
return Mono.fromCompletionStage(updateItem) | |
.flatMap { | |
getHotel(hotel.id) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Hotel( | |
val id: String = UUID.randomUUID().toString(), | |
val name: String, | |
val address: String? = null, | |
val state: String? = null, | |
val zip: String? = null, | |
val version: Long = 1L | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment