Skip to content

Instantly share code, notes, and snippets.

@sebprunier
Created February 20, 2017 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebprunier/d28d53d296adf447545a260e484396cf to your computer and use it in GitHub Desktop.
Save sebprunier/d28d53d296adf447545a260e484396cf to your computer and use it in GitHub Desktop.
def index(page: Int) = Action.async { implicit request =>
for {
api <- fetchApi
response <- api.forms("everything")
.query(
Predicate.at("document.type", "Blog-post")
)
.ref(ref(api))
.orderings("[Blog-post.date]")
.pageSize(10)
.page(page).submit()
} yield {
val newResponse = response.copy(results = response.results.sortWith((a, b) => {
a.getDate("Blog-post.date").map(_.value).getOrElse(LocalDate.now())
.isAfter(b.getDate("Blog-post.date").map(_.value).getOrElse(LocalDate.now()))
}))
Ok(views.html.index(newResponse))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment