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() + } +}