mirror of https://github.com/usbharu/Hideout.git
feat: UserのQueryServiceを追加
This commit is contained in:
parent
2a6edd7da9
commit
dc25dda7fe
|
@ -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<User>
|
||||||
|
suspend fun findByNameAndDomain(name: String, domain: String): User
|
||||||
|
suspend fun findByUrl(url: String): User
|
||||||
|
}
|
|
@ -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<User> {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue