full reborn
This commit is contained in:
.github/workflows
LICENSEREADME.mdbuild.gradlebusiness_cases/post_creating
client
common
src
commonMain
kotlin
dev
inmo
postssystem
business_cases
post_creating
main
server
client
build.gradle
src
commonMain
kotlin
dev
inmo
jsMain
kotlin
dev
resources
jvmMain
kotlin
dev
inmo
postssystem
client
main
core
api
src
commonMain
kotlin
dev
inmo
postssystem
core
commonTest
kotlin
dev
inmo
postssystem
core
jvmMain
kotlin
dev
inmo
postssystem
core
content
api
business
content_adapters
binary
main
exposed
build.gradlegradle.properties
src
jvmMain
kotlin
dev
inmo
postssystem
core
exposed
jvmTest
kotlin
dev
inmo
postssystem
ktor
client
common
src
commonMain
kotlin
dev
inmo
postssystem
main
server
features
auth
client
common
server
common
client
common
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
common
jvmMain
kotlin
dev
inmo
postssystem
features
common
common
main
server
files
client
build.gradle
src
common
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
jvmMain
kotlin
dev
inmo
postssystem
features
main
server
roles
client
common
manager
client
common
server
server
status
template
client
common
server
users
client
common
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
users
jvmMain
kotlin
dev
inmo
postssystem
features
users
common
main
server
gradle/wrapper
gradlewgradlew.batmimes_generator
mppAndroidProject.gradlemppJavaProject.gradlemppJsProject.gradlemppProjectWithSerialization.gradlepubconf.kpsbpublish.gradlepublish.kpsbpublishing
api
src
commonMain
kotlin
main
exposed
ktor
client
src
commonMain
kotlin
com
insanusmokrassar
postssystem
main
common
src
commonMain
kotlin
com
insanusmokrassar
main
server
server
settings.gradle
27
features/users/common/build.gradle
Normal file
27
features/users/common/build.gradle
Normal file
@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.features.common.common")
|
||||
api "dev.inmo:micro_utils.repos.common:$microutils_version"
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api "dev.inmo:micro_utils.repos.exposed:$microutils_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
disableIncludingJvmCodeInAndroidPart()
|
||||
}
|
3
features/users/common/src/commonMain/kotlin/dev/inmo/postssystem/features/users/common/Routes.kt
Normal file
3
features/users/common/src/commonMain/kotlin/dev/inmo/postssystem/features/users/common/Routes.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package dev.inmo.postssystem.features.users.common
|
||||
|
||||
const val usersServerPathPart = "users"
|
46
features/users/common/src/commonMain/kotlin/dev/inmo/postssystem/features/users/common/User.kt
Normal file
46
features/users/common/src/commonMain/kotlin/dev/inmo/postssystem/features/users/common/User.kt
Normal file
@ -0,0 +1,46 @@
|
||||
package dev.inmo.postssystem.features.users.common
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
@Serializable
|
||||
@JvmInline
|
||||
value class UserId(val long: Long) {
|
||||
override fun toString(): String = long.toString()
|
||||
}
|
||||
val Long.userId: UserId
|
||||
get() = UserId(this)
|
||||
|
||||
@Serializable
|
||||
@JvmInline
|
||||
value class Username(val string: String) {
|
||||
override fun toString(): String = string
|
||||
}
|
||||
val String.username: Username
|
||||
get() = Username(this)
|
||||
|
||||
sealed interface NewUser {
|
||||
val firstName: String
|
||||
val lastName: String
|
||||
val username: Username
|
||||
}
|
||||
|
||||
@Serializable
|
||||
sealed class User : NewUser {
|
||||
abstract val id: UserId
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class DefaultUser(
|
||||
override val id: UserId,
|
||||
override val firstName: String,
|
||||
override val lastName: String,
|
||||
override val username: Username,
|
||||
) : User()
|
||||
|
||||
@Serializable
|
||||
data class DefaultNewUser(
|
||||
override val firstName: String,
|
||||
override val lastName: String,
|
||||
override val username: Username,
|
||||
) : NewUser
|
7
features/users/common/src/commonMain/kotlin/dev/inmo/postssystem/features/users/common/UsersStorage.kt
Normal file
7
features/users/common/src/commonMain/kotlin/dev/inmo/postssystem/features/users/common/UsersStorage.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package dev.inmo.postssystem.features.users.common
|
||||
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
|
||||
interface ReadUsersStorage : ReadCRUDRepo<User, UserId>
|
||||
interface WriteUsersStorage : WriteCRUDRepo<User, UserId, NewUser>
|
||||
interface UsersStorage : ReadUsersStorage, WriteUsersStorage, CRUDRepo<User, UserId, NewUser>
|
51
features/users/common/src/jvmMain/kotlin/dev/inmo/postssystem/features/users/common/ExposedUsersStorage.kt
Normal file
51
features/users/common/src/jvmMain/kotlin/dev/inmo/postssystem/features/users/common/ExposedUsersStorage.kt
Normal file
@ -0,0 +1,51 @@
|
||||
package dev.inmo.postssystem.features.users.common
|
||||
|
||||
import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.initTable
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.statements.InsertStatement
|
||||
import org.jetbrains.exposed.sql.statements.UpdateStatement
|
||||
|
||||
class ExposedUsersStorage(override val database: Database) : UsersStorage, AbstractExposedCRUDRepo<User, UserId, NewUser>(
|
||||
tableName = "Users"
|
||||
) {
|
||||
val userIdColumn = long("userid").autoIncrement()
|
||||
val usernameColumn = text("username")
|
||||
private val firstNameColumn = text("firstName")
|
||||
private val lastNameColumn = text("lastName")
|
||||
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(userIdColumn)
|
||||
|
||||
override val selectByIds: SqlExpressionBuilder.(List<UserId>) -> Op<Boolean> = { userIdColumn.inList(it.map { it.long }) }
|
||||
override val selectById: SqlExpressionBuilder.(UserId) -> Op<Boolean> = { userIdColumn.eq(it.long) }
|
||||
override val ResultRow.asObject: User
|
||||
get() = DefaultUser(
|
||||
get(userIdColumn).userId,
|
||||
get(firstNameColumn),
|
||||
get(lastNameColumn),
|
||||
get(usernameColumn).username,
|
||||
)
|
||||
|
||||
init {
|
||||
initTable()
|
||||
}
|
||||
|
||||
override fun insert(value: NewUser, it: InsertStatement<Number>) {
|
||||
it[usernameColumn] = value.username.string
|
||||
it[firstNameColumn] = value.firstName
|
||||
it[lastNameColumn] = value.lastName
|
||||
}
|
||||
|
||||
override fun update(id: UserId, value: NewUser, it: UpdateStatement) {
|
||||
it[usernameColumn] = value.username.string
|
||||
it[firstNameColumn] = value.firstName
|
||||
it[lastNameColumn] = value.lastName
|
||||
}
|
||||
|
||||
override fun InsertStatement<Number>.asObject(value: NewUser): User = DefaultUser(
|
||||
get(userIdColumn).userId,
|
||||
get(firstNameColumn),
|
||||
get(lastNameColumn),
|
||||
get(usernameColumn).username,
|
||||
)
|
||||
}
|
1
features/users/common/src/main/AndroidManifest.xml
Normal file
1
features/users/common/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.postssystem.features.users.common"/>
|
Reference in New Issue
Block a user