From 571f5781d222c6bd66ea06852e26544c89fc04d5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 5 Dec 2021 19:00:38 +0600 Subject: [PATCH] add post preview --- features/common/common/build.gradle | 1 + .../common/common/DateTimeSerializer.kt | 23 +++++++++ features/posts/client/build.gradle | 18 +++++++ .../posts/client/src/main/AndroidManifest.xml | 1 + features/posts/common/build.gradle | 18 +++++++ .../postssystem/features/posts/common/Post.kt | 47 +++++++++++++++++++ .../posts/common/src/main/AndroidManifest.xml | 1 + features/posts/server/build.gradle | 17 +++++++ mppJavaProject.gradle | 7 +-- mppProjectWithSerialization.gradle | 7 +-- settings.gradle | 4 ++ 11 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/DateTimeSerializer.kt create mode 100644 features/posts/client/build.gradle create mode 100644 features/posts/client/src/main/AndroidManifest.xml create mode 100644 features/posts/common/build.gradle create mode 100644 features/posts/common/src/commonMain/kotlin/dev/inmo/postssystem/features/posts/common/Post.kt create mode 100644 features/posts/common/src/main/AndroidManifest.xml create mode 100644 features/posts/server/build.gradle diff --git a/features/common/common/build.gradle b/features/common/common/build.gradle index d88baba6..ab951534 100644 --- a/features/common/common/build.gradle +++ b/features/common/common/build.gradle @@ -14,6 +14,7 @@ kotlin { api "dev.inmo:micro_utils.serialization.typed_serializer:$microutils_version" api "io.insert-koin:koin-core:$koin_version" api "com.benasher44:uuid:$uuid_version" + api "com.soywiz.korlibs.klock:klock:$klock_version" } } jvmMain { diff --git a/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/DateTimeSerializer.kt b/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/DateTimeSerializer.kt new file mode 100644 index 00000000..28f65201 --- /dev/null +++ b/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/DateTimeSerializer.kt @@ -0,0 +1,23 @@ +package dev.inmo.postssystem.features.common.common + +import com.soywiz.klock.DateTime +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializer +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializer(DateTime::class) +object DateTimeSerializer : KSerializer { + override val descriptor: SerialDescriptor + get() = Double.serializer().descriptor + + override fun deserialize(decoder: Decoder): DateTime { + return DateTime(decoder.decodeDouble()) + } + + override fun serialize(encoder: Encoder, value: DateTime) { + encoder.encodeDouble(value.unixMillis) + } +} diff --git a/features/posts/client/build.gradle b/features/posts/client/build.gradle new file mode 100644 index 00000000..e3dd9a05 --- /dev/null +++ b/features/posts/client/build.gradle @@ -0,0 +1,18 @@ +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.posts.common") + api project(":postssystem.features.common.client") + } + } + } +} diff --git a/features/posts/client/src/main/AndroidManifest.xml b/features/posts/client/src/main/AndroidManifest.xml new file mode 100644 index 00000000..1d10bd6b --- /dev/null +++ b/features/posts/client/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/features/posts/common/build.gradle b/features/posts/common/build.gradle new file mode 100644 index 00000000..f4369eca --- /dev/null +++ b/features/posts/common/build.gradle @@ -0,0 +1,18 @@ +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 project(":postssystem.features.content.common") + } + } + } +} diff --git a/features/posts/common/src/commonMain/kotlin/dev/inmo/postssystem/features/posts/common/Post.kt b/features/posts/common/src/commonMain/kotlin/dev/inmo/postssystem/features/posts/common/Post.kt new file mode 100644 index 00000000..a5576f3e --- /dev/null +++ b/features/posts/common/src/commonMain/kotlin/dev/inmo/postssystem/features/posts/common/Post.kt @@ -0,0 +1,47 @@ +package dev.inmo.postssystem.features.posts.common + +import com.soywiz.klock.DateTime +import dev.inmo.postssystem.features.common.common.DateTimeSerializer +import dev.inmo.postssystem.features.content.common.ContentId +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +/** + * Identifier of [RegisteredPost] in system + */ +@Serializable +@JvmInline +value class PostId(val long: Long) { + override fun toString(): String = long.toString() +} +typealias ContentIds = List + +/** + * Base interface for creating of new post + * + * @see NewPost + * @see RegisteredPost + */ +@Serializable +sealed class Post { + abstract val content: ContentIds +} + +/** + * This type of [Post] should be used in case you wish to register new post in system + */ +@Serializable +data class NewPost( + override val content: ContentIds +) : Post() + +/** + * Registered [Post] + */ +@Serializable +data class RegisteredPost( + val id: PostId, + override val content: ContentIds, + @Serializable(DateTimeSerializer::class) + val creationDate: DateTime +) : Post() diff --git a/features/posts/common/src/main/AndroidManifest.xml b/features/posts/common/src/main/AndroidManifest.xml new file mode 100644 index 00000000..6e2b9ccc --- /dev/null +++ b/features/posts/common/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/features/posts/server/build.gradle b/features/posts/server/build.gradle new file mode 100644 index 00000000..b5ad7bf6 --- /dev/null +++ b/features/posts/server/build.gradle @@ -0,0 +1,17 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" +} + +apply from: "$mppJavaProjectPresetPath" + +kotlin { + sourceSets { + commonMain { + dependencies { + api project(":postssystem.features.posts.common") + api project(":postssystem.features.common.server") + } + } + } +} diff --git a/mppJavaProject.gradle b/mppJavaProject.gradle index 2039c0f2..762212c9 100644 --- a/mppJavaProject.gradle +++ b/mppJavaProject.gradle @@ -4,12 +4,7 @@ project.group = "$group" apply from: "$publishGradlePath" kotlin { - jvm().compilations.main { - kotlinOptions { - jvmTarget = "1.8" - targetCompatibility = "1.8" - } - } + jvm() sourceSets { commonMain { diff --git a/mppProjectWithSerialization.gradle b/mppProjectWithSerialization.gradle index 35215f12..dbd59f01 100644 --- a/mppProjectWithSerialization.gradle +++ b/mppProjectWithSerialization.gradle @@ -4,12 +4,7 @@ project.group = "$group" apply from: "$publishGradlePath" kotlin { - jvm().compilations.main { - kotlinOptions { - jvmTarget = "1.8" - targetCompatibility = "1.8" - } - } + jvm() js (IR) { browser() nodejs() diff --git a/settings.gradle b/settings.gradle index 987bb1db..9d7c6da3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -41,6 +41,10 @@ String[] includes = [ ":features:content:binary:client", ":features:content:binary:server", + ":features:posts:common", + ":features:posts:client", + ":features:posts:server", + ":server", ":client", ]