0
私はまだ解決できないコンパイルエラーが1つあります。彼がデータベースにいない場合、新しい患者をmongoに追加するアクションです。まずモデル:Play Scala Framework:タイプミスマッチscala.concurrent.Future [オブジェクト] [エラー]必須:scala.concurrent.Future [play.api.mvc.Result]
case class PatientData(id : String)
object PatientData {
implicit val PatientDataFormat = Json.format[PatientData]
}
モンゴで患者を検索する機能:
def findPatientById(mode : String, id : String) : Future[Option[PatientData]] = {
val collection = getPatientCollection(mode)
collection.find(Json.obj("id" -> id)).one[PatientData]
}
プレイアクション:
def create(patientId: String) = Action.async(parse.json) { request =>
val token = "dummy"
isAuthorized(token) match { // always return Some(thing)
case None => Future.successful(Unauthorized("Invalid token " + token))
case Some(_) =>
request.body.validate[PatientData] map {
patientData =>
findPatientById(mode,patientId) map { finded =>
finded match {
case Some(_) => Future.successful(NotAcceptable("The patient is already exist."))
case None =>
Logger.info("Create the patient .. ")
Future.successful(Created)
}
}
} getOrElse {
Future.successful(BadRequest)
}
}
私はAwait.result
への呼び出しを使用してこの問題を解決することができることを知っていますfindPatientById
の機能では、私はこの解決方法を避けてFuture
の仕事をしたいと思っています。問題は、コンパイルエラーが発生することです。
[error] /home/afk/git/bioserenity/bioserenity-backend/app/controllers/MedataController.scala:90: type mismatch;
[error] found : scala.concurrent.Future[Object]
[error] required: scala.concurrent.Future[play.api.mvc.Result]
[error] } getOrElse {
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
誰でもこの問題を解決するためのアイデアはありますか?
修正ありがとうございます:) – alifirat