``` <http://router.post|router.post>(“/rate/:i...
# vertx
j
Copy code
<http://router.post|router.post>(“/rate/:id”).coroutineHandler { ctx ->
      val movie = Integer.parseInt(ctx.pathParam(“id”))
      val rating = Integer.parseInt(ctx.queryParam(“value”)[0])
      val connection = awaitResult<SQLConnection> { client.getConnection(it) }
      try {
        val result = awaitResult<ResultSet> { connection.queryWithParams(“SELECT TITLE FROM MOVIE WHERE ID=?“, json { array(movie) }, it) }
        if (result.rows.size == 1) {
          awaitResult<UpdateResult> { connection.updateWithParams(“INSERT INTO RATING (VALUE, MOVIE) VALUES ?, ?“, json { array(rating, movie) }, it) }
          ctx.response().setStatusCode(200).end()
        } else {
          ctx.response().setStatusCode(404).end()
        }
      } finally {
        connection.close()
      }
    }
👍 1
1