From dc25dda7feaab767db8f16f4d8a4e4450cc841ae Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 10 Aug 2023 18:22:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20User=E3=81=AEQueryService=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usbharu/hideout/query/UserQueryService.kt | 10 ++++++++ .../hideout/query/UserQueryServiceImpl.kt | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/query/UserQueryService.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/query/UserQueryService.kt b/src/main/kotlin/dev/usbharu/hideout/query/UserQueryService.kt new file mode 100644 index 00000000..2da0512d --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/query/UserQueryService.kt @@ -0,0 +1,10 @@ +package dev.usbharu.hideout.query + +import dev.usbharu.hideout.domain.model.hideout.entity.User + +interface UserQueryService { + suspend fun findById(id: Long): User + suspend fun findByName(name: String): List + suspend fun findByNameAndDomain(name: String, domain: String): User + suspend fun findByUrl(url: String): User +} diff --git a/src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt new file mode 100644 index 00000000..d51938d6 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt @@ -0,0 +1,23 @@ +package dev.usbharu.hideout.query + +import dev.usbharu.hideout.domain.model.hideout.entity.User +import dev.usbharu.hideout.repository.Users +import dev.usbharu.hideout.repository.toUser +import org.jetbrains.exposed.sql.and +import org.jetbrains.exposed.sql.select + +class UserQueryServiceImpl : UserQueryService { + override suspend fun findById(id: Long): User = Users.select { Users.id eq id }.single().toUser() + + override suspend fun findByName(name: String): List { + return Users.select { Users.name eq name }.map { it.toUser() } + } + + override suspend fun findByNameAndDomain(name: String, domain: String): User { + return Users.select { Users.name eq name and (Users.domain eq domain) }.single().toUser() + } + + override suspend fun findByUrl(url: String): User { + return Users.select { Users.url eq url }.single().toUser() + } +}