diff --git a/features/content/binary/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/binary/server/BinaryServerContentStorage.kt b/features/content/binary/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/binary/server/BinaryServerContentStorage.kt index 250c37c1..6c9ffffe 100644 --- a/features/content/binary/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/binary/server/BinaryServerContentStorage.kt +++ b/features/content/binary/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/binary/server/BinaryServerContentStorage.kt @@ -81,4 +81,8 @@ class BinaryServerContentStorage( ) } } + + override suspend fun getContentPreview(id: ContentId): RegisteredContent? { + TODO("Not yet implemented") + } } diff --git a/features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/storage/ServerReadContentStorage.kt b/features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/storage/ServerReadContentStorage.kt index 6c542426..92bd651d 100644 --- a/features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/storage/ServerReadContentStorage.kt +++ b/features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/storage/ServerReadContentStorage.kt @@ -1,7 +1,8 @@ package dev.inmo.postssystem.features.content.server.storage import dev.inmo.micro_utils.repos.ReadCRUDRepo -import dev.inmo.postssystem.features.content.common.ContentId -import dev.inmo.postssystem.features.content.common.RegisteredContent +import dev.inmo.postssystem.features.content.common.* -interface ServerReadContentStorage : ReadCRUDRepo +interface ServerReadContentStorage : ReadCRUDRepo { + suspend fun getContentPreview(id: ContentId): RegisteredContent? +} diff --git a/features/content/text/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/text/server/TextServerContentStorage.kt b/features/content/text/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/text/server/TextServerContentStorage.kt index 2ee63418..e993af4f 100644 --- a/features/content/text/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/text/server/TextServerContentStorage.kt +++ b/features/content/text/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/text/server/TextServerContentStorage.kt @@ -3,13 +3,13 @@ package dev.inmo.postssystem.features.content.text.server import com.benasher44.uuid.uuid4 import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo import dev.inmo.micro_utils.repos.exposed.initTable -import dev.inmo.postssystem.features.content.common.ContentId -import dev.inmo.postssystem.features.content.common.RegisteredContent +import dev.inmo.postssystem.features.content.common.* import dev.inmo.postssystem.features.content.server.storage.ServerContentStorage import dev.inmo.postssystem.features.content.text.common.TextContent import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.statements.InsertStatement import org.jetbrains.exposed.sql.statements.UpdateStatement +import org.jetbrains.exposed.sql.transactions.transaction class TextServerContentStorage( override val database: Database @@ -50,4 +50,19 @@ class TextServerContentStorage( TextContent(get(textColumn)) ) } + + override suspend fun getContentPreview(id: ContentId): RegisteredContent? = transaction(database) { + select { selectById(id) }.limit(1).firstOrNull() ?.let { + val text = it[textColumn] + val postfix = if (text.length > 1024) { + "..." + } else { + "" + } + RegisteredContent( + id, + TextContent(text.take(1024) + postfix) + ) + } + } } diff --git a/services/posts/client/src/commonMain/kotlin/dev/inmo/postssystem/services/posts/client/ui/posts_list/PostsListUIState.kt b/services/posts/client/src/commonMain/kotlin/dev/inmo/postssystem/services/posts/client/ui/posts_list/PostsListUIState.kt new file mode 100644 index 00000000..3702e3fb --- /dev/null +++ b/services/posts/client/src/commonMain/kotlin/dev/inmo/postssystem/services/posts/client/ui/posts_list/PostsListUIState.kt @@ -0,0 +1,15 @@ +package dev.inmo.postssystem.services.posts.client.ui.posts_list + +import dev.inmo.postssystem.features.posts.common.Post +import kotlinx.serialization.Serializable + +@Serializable +sealed class PostsListUIState { + @Serializable + object Loading : PostsListUIState() + @Serializable + data class Show( + val posts: List + ) : PostsListUIState() + +}