In Scala Play and Slick, how to get request to finish before sending response
<p>In Scala Play and Slick, I wish to send a OK response only after a record has been created in the database, so far I've got:</p>

<pre><code>  def createItem = Action(BodyParsers.parse.json) {
    request =&gt; {
      val result = request.body.validate[Item]

      result.fold(
        invalid =&gt; {
          val problem = new Problem(BAD_REQUEST, "Invalid Item JSON", invalid.toString)
          returnProblemResult(BadRequest, problem)
        },
        item =&gt; {
          service.create(item)
          // TODO check for success before sending ok
          Ok.as(ContentTypes("DEFAULT"))
        }
      )
    }
  }
</code></pre>

<p>And inside the service.create method:</p>

<pre><code>  def create(item: Item): Future[Unit] = {
    exists(item.id).map {
      case true =&gt; 
      case _ =&gt; db.run(Item.table += cc)
    }
  }
</code></pre>

<p>Currently, the OK response get sent even if no new item is created. I would like it to only return OK if an item is created. If the item already exists, or if there're other errors (e.g. database errors), the createItem method should know what kind of problem occurred and return a Problem result with error message.</p>