From b152912980f12222ba67d721b0eae58f77c81743 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 10 Aug 2023 19:55:46 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20PostResponse=E3=81=AEQueryService?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/query/PostResponseQueryService.kt | 26 ++++++++++ .../query/PostResponseQueryServiceImpl.kt | 51 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt b/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt new file mode 100644 index 00000000..9386a4ce --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt @@ -0,0 +1,26 @@ +package dev.usbharu.hideout.query + +import dev.usbharu.hideout.domain.model.hideout.dto.PostResponse + +@Suppress("LongParameterList") +interface PostResponseQueryService { + suspend fun findById(id: Long, userId: Long): PostResponse + suspend fun findAll( + since: Long, + until: Long, + minId: Long, + maxId: Long, + limit: Long, + userId: Long + ): List + + suspend fun findByUserId( + userId: Long, + since: Long, + until: Long, + minId: Long, + maxId: Long, + limit: Long, + userId2: Long + ): List +} diff --git a/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt new file mode 100644 index 00000000..858aa05f --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt @@ -0,0 +1,51 @@ +package dev.usbharu.hideout.query + +import dev.usbharu.hideout.domain.model.hideout.dto.PostResponse +import dev.usbharu.hideout.repository.Posts +import dev.usbharu.hideout.repository.Users +import dev.usbharu.hideout.repository.toPost +import dev.usbharu.hideout.repository.toUser +import org.jetbrains.exposed.sql.innerJoin +import org.jetbrains.exposed.sql.select +import org.jetbrains.exposed.sql.selectAll +import org.koin.core.annotation.Single + +@Single +class PostResponseQueryServiceImpl : PostResponseQueryService { + override suspend fun findById(id: Long, userId: Long): PostResponse { + return Posts + .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { Users.id }) + .select { Posts.id eq id } + .single() + .let { PostResponse.from(it.toPost(), it.toUser()) } + } + + override suspend fun findAll( + since: Long, + until: Long, + minId: Long, + maxId: Long, + limit: Long, + userId: Long + ): List { + return Posts + .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id }) + .selectAll() + .map { PostResponse.from(it.toPost(), it.toUser()) } + } + + override suspend fun findByUserId( + userId: Long, + since: Long, + until: Long, + minId: Long, + maxId: Long, + limit: Long, + userId2: Long + ): List { + return Posts + .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id }) + .select { Posts.userId eq userId } + .map { PostResponse.from(it.toPost(), it.toUser()) } + } +}