Created
August 25, 2017 20:54
-
-
Save codemwnci/343ee47a46efecddf17320e7ce330143 to your computer and use it in GitHub Desktop.
Update a todo
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
put(":id") { req, res -> | |
val update = jacksonObjectMapper().readTree(req.body()) | |
if (!update.has("text") || !update.has("done")) badRequest("text and done required in JSON body string") | |
val rowsUpdated = using(sessionOf(HikariCP.dataSource())) { session -> | |
session.run(queryOf("update todo set text=?, done=? where id=?", | |
update.get("text").asText(), update.get("done").asBoolean(), req.params("id").toLong()) | |
.asUpdate) | |
} | |
if (rowsUpdated == 1) jacksonObjectMapper().writeValueAsString(getTodo(req.params("id").toLong())) | |
else serverError("something went wrong") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment