Commit be23f162 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

sort requests by date and limit to 50 by default

parent c0017f46
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class RestHistoryDAOImpl @Inject()(dbConfigProvider: DatabaseConfigProvider) ext
  val requests = TableQuery[RestRequests]

  def all(username: String): Future[Seq[RestRequest]] = {
    dbConfig.db.run(requests.filter(_.username === username).result).map { reqs =>
    dbConfig.db.run(requests.filter(_.username === username).sortBy(_.createdAt.desc).take(50).result).map { reqs =>
      reqs.map { r => RestRequest(r.path, r.method, r.body, r.username, new Date(r.createdAt)) }
    }
  }
+2 −2
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ class RestRequestDAOSpec(implicit ee: ExecutionEnv) extends Specification {
    val dao: RestHistoryDAO = app.injector.instanceOf(classOf[RestHistoryDAO])
    val entries: Future[Seq[RestRequest]] = dao.all("admin")
    val expected: Seq[RestRequest] = Seq(
      RestRequest("somePath", "someMethod", "theBody", "admin", new Date(123)),
      RestRequest("otherPath", "otherMethod", "otherBody", "admin", new Date(currentTime + 100))
      RestRequest("otherPath", "otherMethod", "otherBody", "admin", new Date(currentTime + 100)),
      RestRequest("somePath", "someMethod", "theBody", "admin", new Date(123))
    )
    entries must beEqualTo(expected).await
  }