full reborn

This commit is contained in:
2021-11-24 13:52:27 +06:00
parent 0ac6b0a4df
commit 6a6a197041
246 changed files with 4327 additions and 6952 deletions
.github/workflows
LICENSEREADME.mdbuild.gradle
business_cases/post_creating
client
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
business_cases
post_creating
main
common
src
commonMain
kotlin
dev
inmo
postssystem
main
server
build.gradle
src
jvmMain
kotlin
dev
inmo
postssystem
business_cases
post_creating
client
core
defaultAndroidSettingsdefaultAndroidSettings.gradleextensions.gradle
features
auth
common
client
build.gradle
src
commonMain
kotlin
dev
inmo
main
common
build.gradle
src
commonMain
kotlin
dev
inmo
jvmMain
kotlin
dev
inmo
postssystem
features
main
server
build.gradle
src
jvmMain
kotlin
dev
inmo
postssystem
features
files
client
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
main
common
server
build.gradle
src
jvmMain
kotlin
dev
inmo
postssystem
features
roles
status
client
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
main
common
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
status
main
server
build.gradle
src
jvmMain
kotlin
dev
inmo
postssystem
features
template
users
client
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
main
common
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
jvmMain
kotlin
dev
inmo
postssystem
features
main
server
build.gradle
src
jvmMain
kotlin
dev
inmo
postssystem
gradle.properties
gradle/wrapper
gradlewgradlew.bat
mimes_generator
mppAndroidProject.gradlemppJavaProject.gradlemppJsProject.gradlemppProjectWithSerialization.gradlepubconf.kpsbpublish.gradlepublish.kpsb
publishing
server
settings.gradle

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

@ -0,0 +1,3 @@
package dev.inmo.postssystem.features.users.common
const val usersServerPathPart = "users"

@ -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

@ -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>

@ -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,
)
}

@ -0,0 +1 @@
<manifest package="dev.inmo.postssystem.features.users.common"/>