-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14-Paged.kt
31 lines (30 loc) · 930 Bytes
/
14-Paged.kt
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
27
28
29
30
31
@JsonInclude(JsonInclude.Include.NON_NULL)
data class Paged<T>(
val items: Collection<T>,
val page: Int,
val pageSize: Int,
val total: Long,
val sort: String?,
val sortDir: Sort.Direction?,
) {
companion object {
fun <T> of(items: Collection<T>, total: Long, page: Pageable): Paged<T> =
Paged(
items = items,
page = page.pageNumber,
pageSize = page.pageSize,
total = total,
sort = page.sort.map { it.property }.joinToString(","),
sortDir = page.sort.map { it.direction }.firstOrNull(),
)
}
}
fun <T> Page<T>.toPaged(): Paged<T> =
Paged(
items = content,
page = number,
pageSize = size,
total = totalElements,
sort = sort.map { it.property }.joinToString(","),
sortDir = sort.map { it.direction }.firstOrNull(),
)