in software/src/main/kotlin/com/amazonaws/sample/DeleteProductHandler.kt [24:52]
override fun handleRequest(event: APIGatewayV2HTTPEvent, context: Context): APIGatewayV2HTTPResponse {
val logger = context.logger
val id = event.pathParameters?.get("id") ?: return missingId()
try {
runBlocking {
dynamoDbClient.deleteItem(
DeleteItemRequest {
tableName = productTable
key = mapOf("PK" to AttributeValue.S(id))
}
)
}
} catch (e: Exception) {
logger.log("ERROR ${e.message}")
return APIGatewayV2HTTPResponse().apply {
statusCode = 500
headers = mapOf("Content-Type" to "application/json")
body = """{"message": "Failed to delete product"}"""
}
}
return APIGatewayV2HTTPResponse().apply {
statusCode = 200
headers = mapOf("Content-Type" to "application/json")
body = """{"message": "Product deleted"}"""
}
}