Alexis Hernandez
7 years ago
2 changed files with 25 additions and 0 deletions
@ -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) } |
||||
|
} |
@ -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…
Reference in new issue