From 34c62e596ee8e8e81250a4bf88d01fc3719c0fec Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 29 Jan 2024 17:59:02 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=9A=E3=83=BC=E3=82=B8=E3=83=8D?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E6=83=85=E5=A0=B1=E3=82=92?= =?UTF-8?q?=E6=8C=81=E3=81=A4PaginationList=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/exposed/PaginationList.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationList.kt 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(",") +}