Progress on adding game search api

This commit is contained in:
Mark Henle 2017-01-05 20:13:39 -05:00
parent e99c2233fd
commit 17ce28a39b
4 changed files with 32 additions and 3 deletions

View file

@ -50,10 +50,13 @@ object Search extends LilaController {
failure => Ok(html.search.index(failure, none, nbGames)).fuccess,
data => data.nonEmptyQuery ?? { query =>
env.paginator(query, page) map (_.some)
} map { pager =>
Ok(_)
} map { pager => pager match {
case Some(s) => Env.search.jsonView.showResults(s)
case None => Ok("Hello World")
}
}
)
)
}
}
}

View file

@ -16,6 +16,8 @@ final class Env(
private val Writeable = config getBoolean "writeable"
private val Endpoint = config getString "endpoint"
lazy val jsonView = new JsonView()
val makeClient = (index: Index) =>
if (Enabled) new ESClientHttp(Endpoint, index, Writeable)
else new ESClientStub

View file

@ -0,0 +1,24 @@
package lila.search
import play.api.libs.json._
import play.api.mvc.Result
import play.api.mvc.Results._
import play.api.data._
import play.api.data.Forms._
import lila.common.LightUser
import lila.common.paginator._
import lila.common.PimpedJson._
import lila.game.Game
final class JsonView() {
def showResults(pager: Paginator[Game]): Result =
Ok(PaginatorJson(pager.mapResults { g =>
Json.obj(
"id" -> g.id
)
})
)
}

View file

@ -135,7 +135,7 @@ object ApplicationBuild extends Build {
libraryDependencies ++= Seq(findbugs, spray.caching) ++ provided(play.api, reactivemongo.driver)
)
lazy val search = project("search", Seq(common, hub)).settings(
lazy val search = project("search", Seq(common, game, hub)).settings(
libraryDependencies ++= provided(play.api)
)