Skip to content

Commit

Permalink
feat: Helper method for Paginated
Browse files Browse the repository at this point in the history
  • Loading branch information
tallnato committed Dec 3, 2019
1 parent 8072fc1 commit 6cbae3a
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,29 @@ package tech.youclap.klap.core.model.paginated
data class Paginated<T>(
val data: T,
val page: Page
)
) {
companion object {
fun <D> from(result: D, page: Int, per: Int, total: Long): Paginated<D> {

val position = Position(
current = page,
max = (total / per).toInt()
)

val data = Data(
per = per,
total = total
)

val paginationPage = Page(
position = position,
data = data
)

return Paginated(
data = result,
page = paginationPage
)
}
}
}

0 comments on commit 6cbae3a

Please sign in to comment.