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 DynamoCat( | |
@DynamoKtPartitionKey | |
val ownerId: Int, | |
@DynamoKtSortKey | |
@DynamoKtSecondaryPartitionKey(indexNames = ["names"]) | |
val name: String, | |
val gender: String, | |
val features: List<String> |
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
@DynamoDbBean | |
data class DynamoCat( | |
@get:DynamoDbPartitionKey var ownerId: Int? = null, | |
@get:DynamoDbSortKey | |
@get:DynamoDbSecondaryPartitionKey(indexNames = ["names"]) | |
var name: String? = null, | |
var gender: String? = null, |
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
// create a data class model, making sure to give it a partition key | |
data class Cat( | |
@DynamoKtPartitionKey val name: String, | |
val lives: Int = 9, | |
) | |
// use the new table schema provided by this module to init the table mapper | |
val tableSchema = DataClassTableSchema(Cat::class) | |
val cats = DynamoDbEnhancedClient.create().table("cats", tableScema) |
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 Cat( | |
val id: String, | |
val name: String, | |
val ownerId: String, | |
val ownerName: String, | |
val colours: Set<Colour>, // replaced grey and brown with this | |
val breed: Breed?, | |
val appointments: List<Instant>, | |
val favouriteFood: String? = null | |
) |
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 Cat( | |
val id: String, | |
val name: String, | |
val ownerId: String, | |
val ownerName: String, | |
val brown: Boolean, | |
val grey: Boolean, | |
val breed: Breed?, | |
val appointments: List<Instant>, | |
val favouriteFood: String? = null // new field; defaulting to null for backwards compatibility |
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
fun main() { | |
val v1 = CatsDao.v1(ClientV1("http://catdocs.com")) | |
val v2 = CatsDao.v2(ClientV2("https://api.catdocs.com")) | |
val backCompat = CatsDao.backCompat(v1 = v1, v2 = v2) | |
val apiFeatureFlag = FeatureFlag.static( | |
treatments = mapOf("123" to "v1", "b692b290-40c4-4c0f-89ac-ed0a537e1736" to "v2"), | |
default = "v2" | |
) |
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
class CatUi(private val cats: CatsDao) { | |
fun renderCatHtml(id: String): String { | |
val cat = cats[id] ?: return "<h1>Cat $id not found</h1>" | |
val isBrown = if (cat.brown) "Yes" else "No" | |
val isGrey = if (cat.grey) "Yes" else "No" | |
val latestAppointment = cat.appointments.maxOrNull() | |
val optionalField = if (cat.favouriteFood != null) { |
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
fun CatsDao.Companion.v1(client: ClientV1) = CatsDao { id -> | |
client[id.toInt()] | |
} |
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
class ClientV2(host: String) { | |
object Lenses { | |
val catId = Path.uuid().of("id") | |
val cat = Body.auto<CatDtoV2>().toLens() | |
val appointments = Body.auto<List<AppointmentDtoV2>>().toLens() | |
} | |
private val backend = ClientFilters.SetHostFrom(Uri.of(host)) |
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
class ClientV2(host: String) { | |
object Lenses { | |
val catId = Path.uuid().of("id") | |
val cat = Body.auto<CatDtoV2>().toLens() | |
val appointments = Body.auto<List<AppointmentDtoV2>>().toLens() | |
} | |
private val backend = ClientFilters.SetHostFrom(Uri.of(host)) |