updates in posts repos, content repos and build scripts
This commit is contained in:
parent
92ab01ee9d
commit
c3326157da
@ -7,7 +7,7 @@ buildscript {
|
||||
}
|
||||
|
||||
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-serialization:$kotlin_version"
|
||||
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$dexcount_version"
|
||||
|
@ -1,8 +1,10 @@
|
||||
package dev.inmo.postssystem.features.content.common
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
@Serializable
|
||||
@JvmInline
|
||||
value class ContentId(val string: String)
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,6 @@ kotlin {
|
||||
dependencies {
|
||||
api project(":postssystem.features.content.common")
|
||||
api project(":postssystem.features.common.server")
|
||||
api project(":postssystem.features.content.server")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,7 @@ object RoleSerializer : KSerializer<Role> {
|
||||
private val serializers = mutableMapOf<String, KSerializer<out Role>>()
|
||||
override val descriptor: SerialDescriptor = String.serializer().descriptor
|
||||
|
||||
@InternalSerializationApi
|
||||
@OptIn(InternalSerializationApi::class)
|
||||
override fun deserialize(decoder: Decoder): Role {
|
||||
return if (decoder is JsonDecoder) {
|
||||
val originalJson = decoder.decodeJsonElement().jsonObject
|
||||
@ -48,7 +48,7 @@ object RoleSerializer : KSerializer<Role> {
|
||||
return userRoleFormat.encodeToJsonElement(this::class.serializer() as KSerializer<T>, this)
|
||||
}
|
||||
|
||||
@InternalSerializationApi
|
||||
@OptIn(InternalSerializationApi::class)
|
||||
override fun serialize(encoder: Encoder, value: Role) {
|
||||
if (encoder is JsonEncoder) {
|
||||
if (value is UnknownRole) {
|
||||
|
@ -13,7 +13,7 @@ kotlin_version=1.6.10
|
||||
kotlin_serialisation_core_version=1.3.2
|
||||
|
||||
koin_version=3.1.2
|
||||
microutils_version=0.9.0
|
||||
microutils_version=0.9.1
|
||||
ktor_version=1.6.7
|
||||
logback_version=1.2.10
|
||||
uuid_version=0.3.1
|
||||
|
2938
kotlin-js-store/yarn.lock
Normal file
2938
kotlin-js-store/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@ -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.text.common.TextContentSerializerModuleConfigurator
|
||||
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.PublicationTarget
|
||||
import dev.inmo.postssystem.targets.telegram.publication.server.PublicationTargetTelegram
|
||||
@ -173,6 +175,9 @@ fun getDIModule(
|
||||
|
||||
single<ServerContentStorage<Content>> { ServerContentStorageAggregator(getAll(), get()) }
|
||||
|
||||
// Posts storage
|
||||
single<ServerPostsStorage> { ExposedServerPostsStorage(get()) }
|
||||
|
||||
// Routing configurators
|
||||
singleWithBinds { FilesRoutingConfigurator(get(), null, get()) }
|
||||
singleWithBinds { StatusRoutingConfigurator }
|
||||
|
Loading…
Reference in New Issue
Block a user