Created
November 30, 2019 10:20
-
-
Save toantran-ea/1cadb2db9a4bbfa0b0771bec57fde10e to your computer and use it in GitHub Desktop.
Data Model 2
This file contains hidden or 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
@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