get {
pagination { page =>
format { format =>
...
def pagination: Directive1[DateSelection] =
parameterMap.flatMap { params =>
(params.get(FromDateKey).map(_.toString), params.get(ToDateKey).map(_.toString), params.get(LimitKey).map(_.toInt)) match {
case (Some(fromDate), Some(toDate), limit) => provide(FromToDate(fromDate, toDate, limit))
case (Some(fromDate), None, limit) => provide(FromDate(fromDate, limit))
case (None, Some(toDate), limit) => provide(ToDate(toDate, limit))
case _ => reject(MalformedPaginationRejection("Invalid pagination data", None))
}
}
...
}
page match {
case f:FromDate => UsageLoggers.fetchLogs(userIds, deviceIds, recipeIds, f, MongoDBObject.empty)
case t:ToDate => UsageLoggers.fetchLogs(userIds, deviceIds, recipeIds, t, MongoDBObject.empty)
case ft:FromToDate => UsageLoggers.fetchLogs(userIds, deviceIds, recipeIds, ft, MongoDBObject.empty)
}
def fetchLogs(magnet: PaginationMagnet): Future[PagedUsage] = magnet()
sealed trait DateSelection
case class FromDate(fromDate:DateTime, limit:Option[Int]) extends DateSelection
case class ToDate(toDate:DateTime, limit:Option[Int]) extends DateSelection
case class FromToDate(fromDate:DateTime, toDate:DateTime, limit:Option[Int]) extends DateSelection
sealed trait PaginationMagnet {
def apply(): Future[PagedUsage]
}
implicit def implicitFromDate(tuple: (List[ObjectId],..., FromDate)) = new PaginationMagnet {
def apply(): Future[PagedUsage] = { .. }
}
implicit def implicitToDate(tuple: (List[ObjectId], ...., ToDate)) = new PaginationMagnet {
def apply(): Future[PagedUsage] = {..}
}
--
You received this message because you are subscribed to the Google Groups "spray.io User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
Visit this group at https://groups.google.com/group/spray-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/a8160146-3851-4735-ad58-f9716a40ca71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/c7b35f88-fb5b-4233-b1af-0ef9fe6ac303%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "spray.io User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spray-user/WLFUnBYeuS8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spray-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/CE7D5976-3935-467C-9DD1-727BE5435ECD%40gmail.com.