62 lines
1.4 KiB
Kotlin
62 lines
1.4 KiB
Kotlin
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.Content
|
|
import dev.inmo.postssystem.features.content.common.ContentId
|
|
import kotlinx.serialization.Polymorphic
|
|
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<ContentId>
|
|
|
|
/**
|
|
* Base interface for creating of new post
|
|
*
|
|
* @see NewPost
|
|
* @see RegisteredPost
|
|
*/
|
|
@Serializable
|
|
sealed interface Post {
|
|
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
|
|
|
|
@Serializable
|
|
data class PostWithContent(
|
|
val post: Post,
|
|
val content: List<@Polymorphic Content>
|
|
)
|
|
|
|
@Serializable
|
|
data class RegisteredPostWithContent(
|
|
val post: RegisteredPost,
|
|
val content: List<@Polymorphic Content>
|
|
)
|