私は多くのビジネスロジックを持つコントローラを持っています。Action.asyncコードブロック内に移動したいと思います。このコードは、私がdocummentation、create a Future[Result]に関連する何かをチェックしてきたが、私はことはできないのです、私は別のクラス(サービス)Action.asyncの内部にあるコード?:プレイフレームワーク2.5コントローラからサービスへのAction.asyncロジックの移動
def tweetsnew(query: String) = Action.async {
// Move From Here...
credentials.map {
case (consumerKey, requestToken) =>
ws.url("https://api.twitter.com/1.1/search/tweets.json")
.sign(OAuthCalculator(consumerKey, requestToken))
.withQueryString("q" -> query)
.withQueryString("max_id" -> "833342796736167936")
.get().map { twitterResponse =>
if (twitterResponse.status == 200) {
// Here There Are More Complex Logic
Ok("That is fine: "+twitterResponse.body)
} else {
throw new Exception(s"Could not retrieve tweets for $query query term")
}
}
}.getOrElse {
Future.failed(new Exception("You did not correctly configure the Twitter credentials"))
}
//....To Here. To Another Class
}
に移動することができますどのように、作品関数がAction.asyncが期待するのと同じ型を返すようにします。
ありがとうございます@vdebegue良い解決策です。私は別の解決策を提案したいと思います。 –