diff --git a/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationList.kt b/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationList.kt new file mode 100644 index 00000000..9bb2239b --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationList.kt @@ -0,0 +1,22 @@ +package dev.usbharu.hideout.application.infrastructure.exposed + +class PaginationList(list: List, val next: ID?, val prev: ID?) : List by list + +fun PaginationList.toHttpHeader( + nextBlock: (string: String) -> String, + prevBlock: (string: String) -> String +): String? { + val mutableListOf = mutableListOf() + 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(",") +}