Browse Source

server: Add the PaginatedResult model

scalafmt-draft
Alexis Hernandez 7 years ago
parent
commit
9db6f8f2c2
  1. 10
      server/app/com/xsn/explorer/models/base/Count.scala
  2. 15
      server/app/com/xsn/explorer/models/base/PaginatedResult.scala

10
server/app/com/xsn/explorer/models/base/Count.scala

@ -0,0 +1,10 @@
package com.xsn.explorer.models.base
import play.api.libs.json.{JsNumber, Writes}
case class Count(int: Int) extends AnyVal
object Count {
implicit val writes: Writes[Count] = Writes[Count] { count => JsNumber(count.int) }
}

15
server/app/com/xsn/explorer/models/base/PaginatedResult.scala

@ -0,0 +1,15 @@
package com.xsn.explorer.models.base
import play.api.libs.json.{Json, OWrites, Writes}
case class PaginatedResult[T](offset: Offset, limit: Limit, total: Count, data: List[T])
object PaginatedResult {
implicit def writes[T](implicit writesT: Writes[T]): Writes[PaginatedResult[T]] = OWrites[PaginatedResult[T]] { result =>
Json.obj(
"offset" -> result.offset,
"limit" -> result.limit,
"total" -> result.total,
"data" -> result.data
)
}
}
Loading…
Cancel
Save