jeudi 7 avril 2016

type mismatch scala.concurrent.Future with Slick & Play Framework

Hello,

    def getMessages(code:String,offset:Option[Int]) = Action.async(parse.json){request =>

    val forPC = (request.body \ "forPC").asOpt[Boolean]

    Talk.findByCode(code).map(_ match{
        case Success(talk) =>
            val talkId = talk.id
            Message.getMessages(talkId=talkId,offset=offset.getOrElse(0), forPC ).map(_ match {
                case Seq(Tables.Messages) => Ok("Cool")
                case    _ => Ok("No")
            })
        case Failure(e) =>
            Logger.error(e.getMessage)
            NotAcceptable(Json.toJson(Map(
                "error" -> "failed"
            )))
    })

And in the Model i have :

// talks by Code
  def findByCode(code: String, conferenceid : Int) = {
    val query = talks.filter(talk => talk.conferenceId === conferenceid && talk.code === code)
    db.run(query.result.head.asTry)
  }


    def getMessages(talkId:Int ,offset:Int, forPC: Option[Boolean]) = {
    val forPCVal = forPC.getOrElse(false)
    //ordering by talkId because it's faster than timestamp
    val query = messages.filter(msg => msg.talkId === talkId && msg.forpc === forPCVal ).sortBy(_.idmessage.desc).drop(offset).take(10).result
    db.run(query)
}

So Play is waiting for Result ( Action ) , and it displays this error :

type mismatch;
 found   : scala.concurrent.Future[play.api.mvc.Result]
 required: play.api.mvc.Result

and this :

enter image description here

Can anyone explain to why this error and give me some hints to solve it ?

Thank you




Aucun commentaire:

Enregistrer un commentaire