blob: 33815427bfd26529d8a46c8232a9e0d890900c88 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package xyz.driver.pdsuicommon.parsers
import xyz.driver.pdsuicommon.db._
import scala.util._
object PaginationParser {
@deprecated("play-akka transition", "0")
def parse(query: Map[String, Seq[String]]): Try[Pagination] =
parse(query.toSeq.flatMap{ case (key, values) =>
values.map(value => key -> value)
})
def parse(query: Seq[(String, String)]): Try[Pagination] = {
val IntString = """\d+""".r
def validate(field: String) = query.collectFirst{case (`field`, size) => size} match {
case Some(IntString(x)) => x.toInt
case Some(str) => throw new ParseQueryArgException((field, s"must be an integer (found $str)"))
case None => throw new ParseQueryArgException((field, "must be defined"))
}
Try {
Pagination(validate("pageSize"), validate("pageNumber"))
}
}
}
|