Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32337ec308 |
@@ -15,6 +15,7 @@ import me.liuwj.ktorm.database.Database
|
|||||||
import org.koin.dsl.bind
|
import org.koin.dsl.bind
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koin.dsl.onClose
|
import org.koin.dsl.onClose
|
||||||
|
import org.mapstruct.factory.Mappers
|
||||||
import javax.sql.DataSource
|
import javax.sql.DataSource
|
||||||
|
|
||||||
private fun hikariDataSource(conf: DataSourceConfig): HikariDataSource {
|
private fun hikariDataSource(conf: DataSourceConfig): HikariDataSource {
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ import org.mapstruct.Mapper
|
|||||||
|
|
||||||
@Mapper(uses = [UserEntityFactory::class])
|
@Mapper(uses = [UserEntityFactory::class])
|
||||||
internal interface UserConverter {
|
internal interface UserConverter {
|
||||||
fun toUser(userEntity: UserEntity): User
|
fun convertToUser(userEntity: UserEntity): User
|
||||||
fun toPersistedUser(userEntity: UserEntity): PersistedUser
|
fun convertToPersistedUser(userEntity: UserEntity): PersistedUser
|
||||||
fun toEntity(user: User): UserEntity
|
fun convertToEntity(user: User): UserEntity
|
||||||
fun toEntity(user: PersistedUser): UserEntity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class UserEntityFactory : Entity.Factory<UserEntity>()
|
internal class UserEntityFactory : Entity.Factory<UserEntity>()
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ internal class UserRepositoryImpl(private val db: Database, private val converte
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun find(username: String) = db.users.find { it.username eq username }
|
override fun find(username: String) = db.users.find { it.username eq username }
|
||||||
?.let { converter.toPersistedUser(it) }
|
?.let { converter.convertToPersistedUser(it) }
|
||||||
|
|
||||||
override fun find(id: Int) = db.users.find { it.id eq id }?.let {
|
override fun find(id: Int) = db.users.find { it.id eq id }?.let {
|
||||||
converter.toPersistedUser(it)
|
converter.convertToPersistedUser(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun exists(username: String) = db.users.any { it.username eq username }
|
override fun exists(username: String) = db.users.any { it.username eq username }
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ internal class UserConverterTest {
|
|||||||
}.apply {
|
}.apply {
|
||||||
this["id"] = 2
|
this["id"] = 2
|
||||||
}
|
}
|
||||||
val user = converter.toUser(entity)
|
val user = converter.convertToUser(entity)
|
||||||
assertThat(user).isEqualTo(User("test", "test2"))
|
assertThat(user).isEqualTo(User("test", "test2"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ internal class UserConverterTest {
|
|||||||
}.apply {
|
}.apply {
|
||||||
this["id"] = 2
|
this["id"] = 2
|
||||||
}
|
}
|
||||||
val user = converter.toPersistedUser(entity)
|
val user = converter.convertToPersistedUser(entity)
|
||||||
assertThat(user).isEqualTo(PersistedUser("test", "test2", 2))
|
assertThat(user).isEqualTo(PersistedUser("test", "test2", 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ internal class UserConverterTest {
|
|||||||
fun `convert User to UserEntity`() {
|
fun `convert User to UserEntity`() {
|
||||||
val converter = Mappers.getMapper(UserConverter::class.java)
|
val converter = Mappers.getMapper(UserConverter::class.java)
|
||||||
val user = User("test", "test2")
|
val user = User("test", "test2")
|
||||||
val entity = converter.toEntity(user)
|
val entity = converter.convertToEntity(user)
|
||||||
|
|
||||||
assertThat(entity)
|
assertThat(entity)
|
||||||
.hasFieldOrPropertyWithValue("username", "test")
|
.hasFieldOrPropertyWithValue("username", "test")
|
||||||
|
|||||||
Reference in New Issue
Block a user