feat: ページネーション情報を持つPaginationListを追加

This commit is contained in:
usbharu 2024-01-29 17:59:02 +09:00
parent 613afdffef
commit ba6e21decd
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package dev.usbharu.hideout.application.infrastructure.exposed
class PaginationList<T, ID>(list: List<T>, val next: ID?, val prev: ID?) : List<T> by list
fun <T, ID> PaginationList<T, ID>.toHttpHeader(
nextBlock: (string: String) -> String,
prevBlock: (string: String) -> String
): String? {
val mutableListOf = mutableListOf<String>()
if (next != null) {
mutableListOf.add("<${nextBlock(nextBlock.toString())}>; rel=\"next\";")
}
if (prev != null) {
mutableListOf.add("<${prevBlock(prevBlock.toString())}>; rel=\"prev\";")
}
if (mutableListOf.isEmpty()) {
return null
}
return mutableListOf.joinToString(",")
}