updates in posts repos, content repos and build scripts

This commit is contained in:
InsanusMokrassar 2022-01-08 16:00:05 +06:00
parent 92ab01ee9d
commit c3326157da
8 changed files with 3043 additions and 5 deletions

View File

@ -7,7 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.2.2' classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$dexcount_version" classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$dexcount_version"

View File

@ -1,8 +1,10 @@
package dev.inmo.postssystem.features.content.common package dev.inmo.postssystem.features.content.common
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline
@Serializable @Serializable
@JvmInline
value class ContentId(val string: String) value class ContentId(val string: String)
/** /**

View File

@ -11,7 +11,6 @@ kotlin {
dependencies { dependencies {
api project(":postssystem.features.content.common") api project(":postssystem.features.content.common")
api project(":postssystem.features.common.server") api project(":postssystem.features.common.server")
api project(":postssystem.features.content.server")
} }
} }
} }

View File

@ -0,0 +1,94 @@
package dev.inmo.postssystem.features.posts.server
import com.soywiz.klock.DateTime
import dev.inmo.micro_utils.repos.exposed.*
import dev.inmo.postssystem.features.content.common.ContentId
import dev.inmo.postssystem.features.posts.common.*
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.statements.InsertStatement
import org.jetbrains.exposed.sql.statements.UpdateStatement
private class PostsContentsRelations(
override val database: Database,
postIdColumn: Column<Long>
) : Table("PostsContentsRelations"), ExposedRepo {
val postIdColumn = long("postid").references(postIdColumn)
val contentIdColumn = text("contentId")
}
class ExposedServerPostsStorage(
override val database: Database,
) : ServerPostsStorage, AbstractExposedCRUDRepo<RegisteredPost, PostId, NewPost>(
tableName = "Posts"
) {
val idColumn = long("id").autoIncrement()
private val datetimeColumn = long("creationDT")
override val primaryKey: PrimaryKey = PrimaryKey(idColumn)
private val subrepo = PostsContentsRelations(
database,
idColumn
)
private fun getContentInTransaction(id: PostId): List<ContentId> {
return subrepo.select { subrepo.postIdColumn.eq(id.long) }.map { it[subrepo.contentIdColumn].let(::ContentId) }
}
override val selectByIds: SqlExpressionBuilder.(List<PostId>) -> Op<Boolean> = {
idColumn.inList(it.map { it.long })
}
override val selectById: SqlExpressionBuilder.(PostId) -> Op<Boolean> = {
idColumn.eq(it.long)
}
override val ResultRow.asObject: RegisteredPost
get() {
val id = get(idColumn).let(::PostId)
return RegisteredPost(
get(idColumn).let(::PostId),
getContentInTransaction(id),
get(datetimeColumn).let(DateTime::fromUnix)
)
}
init {
initTable()
subrepo.initTable()
}
override fun insert(value: NewPost, it: InsertStatement<Number>) {
it[datetimeColumn] = DateTime.now().unixMillisLong
}
override fun update(id: PostId, value: NewPost, it: UpdateStatement) {
it[datetimeColumn] = DateTime.now().unixMillisLong
subrepo.deleteWhere {
subrepo.postIdColumn.eq(id.long)
}
value.content.map { it.string }.forEach { contentId ->
subrepo.insert {
it[subrepo.postIdColumn] = id.long
it[subrepo.contentIdColumn] = contentId
}
}
}
override fun InsertStatement<Number>.asObject(value: NewPost): RegisteredPost {
val id = get(idColumn).let(::PostId)
value.content.map { it.string }.forEach { contentId ->
subrepo.insert {
it[subrepo.postIdColumn] = id.long
it[subrepo.contentIdColumn] = contentId
}
}
return RegisteredPost(
get(idColumn).let(::PostId),
getContentInTransaction(id),
get(datetimeColumn).let(DateTime::fromUnix)
)
}
}

View File

@ -24,7 +24,7 @@ object RoleSerializer : KSerializer<Role> {
private val serializers = mutableMapOf<String, KSerializer<out Role>>() private val serializers = mutableMapOf<String, KSerializer<out Role>>()
override val descriptor: SerialDescriptor = String.serializer().descriptor override val descriptor: SerialDescriptor = String.serializer().descriptor
@InternalSerializationApi @OptIn(InternalSerializationApi::class)
override fun deserialize(decoder: Decoder): Role { override fun deserialize(decoder: Decoder): Role {
return if (decoder is JsonDecoder) { return if (decoder is JsonDecoder) {
val originalJson = decoder.decodeJsonElement().jsonObject val originalJson = decoder.decodeJsonElement().jsonObject
@ -48,7 +48,7 @@ object RoleSerializer : KSerializer<Role> {
return userRoleFormat.encodeToJsonElement(this::class.serializer() as KSerializer<T>, this) return userRoleFormat.encodeToJsonElement(this::class.serializer() as KSerializer<T>, this)
} }
@InternalSerializationApi @OptIn(InternalSerializationApi::class)
override fun serialize(encoder: Encoder, value: Role) { override fun serialize(encoder: Encoder, value: Role) {
if (encoder is JsonEncoder) { if (encoder is JsonEncoder) {
if (value is UnknownRole) { if (value is UnknownRole) {

View File

@ -13,7 +13,7 @@ kotlin_version=1.6.10
kotlin_serialisation_core_version=1.3.2 kotlin_serialisation_core_version=1.3.2
koin_version=3.1.2 koin_version=3.1.2
microutils_version=0.9.0 microutils_version=0.9.1
ktor_version=1.6.7 ktor_version=1.6.7
logback_version=1.2.10 logback_version=1.2.10
uuid_version=0.3.1 uuid_version=0.3.1

2938
kotlin-js-store/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,8 @@ import dev.inmo.postssystem.features.content.server.ServerContentStorage
import dev.inmo.postssystem.features.content.server.ServerContentStorageAggregator import dev.inmo.postssystem.features.content.server.ServerContentStorageAggregator
import dev.inmo.postssystem.features.content.text.common.TextContentSerializerModuleConfigurator import dev.inmo.postssystem.features.content.text.common.TextContentSerializerModuleConfigurator
import dev.inmo.postssystem.features.content.text.server.TextServerContentStorage import dev.inmo.postssystem.features.content.text.server.TextServerContentStorage
import dev.inmo.postssystem.features.posts.server.ExposedServerPostsStorage
import dev.inmo.postssystem.features.posts.server.ServerPostsStorage
import dev.inmo.postssystem.features.publication.server.PublicationManager import dev.inmo.postssystem.features.publication.server.PublicationManager
import dev.inmo.postssystem.features.publication.server.PublicationTarget import dev.inmo.postssystem.features.publication.server.PublicationTarget
import dev.inmo.postssystem.targets.telegram.publication.server.PublicationTargetTelegram import dev.inmo.postssystem.targets.telegram.publication.server.PublicationTargetTelegram
@ -173,6 +175,9 @@ fun getDIModule(
single<ServerContentStorage<Content>> { ServerContentStorageAggregator(getAll(), get()) } single<ServerContentStorage<Content>> { ServerContentStorageAggregator(getAll(), get()) }
// Posts storage
single<ServerPostsStorage> { ExposedServerPostsStorage(get()) }
// Routing configurators // Routing configurators
singleWithBinds { FilesRoutingConfigurator(get(), null, get()) } singleWithBinds { FilesRoutingConfigurator(get(), null, get()) }
singleWithBinds { StatusRoutingConfigurator } singleWithBinds { StatusRoutingConfigurator }