Skip to content

Instantly share code, notes, and snippets.

@toantran-ea
Created November 30, 2019 10:20
Show Gist options
  • Save toantran-ea/1cadb2db9a4bbfa0b0771bec57fde10e to your computer and use it in GitHub Desktop.
Save toantran-ea/1cadb2db9a4bbfa0b0771bec57fde10e to your computer and use it in GitHub Desktop.
Data Model 2
@Serializable
data class FoodEntry(
val id: String = UUID.randomUUID().toString(),
val name: String,
val time: Long = System.currentTimeMillis(),
val description: String,
val energyCount: Long = 0,
val updated: Long = System.currentTimeMillis()
)
// WebApplication - and update our post method as well
post("entries") {
val entries = fromJsonStringToList(call.receiveTextWithCorrectEncoding())
val savedKeys = dataRepo.save(entries)
call.respondText(contentType = ContentType.Application.Json) {
Json.stringify(String.serializer().list, savedKeys.map { it.name })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment