42 lines
1.0 KiB
Kotlin
42 lines
1.0 KiB
Kotlin
package dev.inmo.postssystem.core.content
|
|
|
|
import kotlinx.serialization.Serializable
|
|
import kotlinx.serialization.modules.*
|
|
|
|
typealias ContentId = String
|
|
|
|
/**
|
|
* Content which is planned to be registered in database
|
|
*/
|
|
interface Content
|
|
|
|
/**
|
|
* That is a content which in fact just a link to another content. It would be useful in case when user wish to reuse
|
|
* some content
|
|
*/
|
|
@Serializable
|
|
data class OtherContentLinkContent(
|
|
val otherId: ContentId
|
|
) : Content
|
|
|
|
|
|
fun SerializersModuleBuilder.includeContentsSerializers(
|
|
block: PolymorphicModuleBuilder<Content>.() -> Unit
|
|
) {
|
|
polymorphic(Content::class) {
|
|
subclass(OtherContentLinkContent::class, OtherContentLinkContent.serializer())
|
|
block()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Content which is already registered in database. Using its [id] you can retrieve all known
|
|
* [dev.inmo.postssystem.core.post.RegisteredPost]s by using
|
|
* [dev.inmo.postssystem.core.post.repo.ReadPostsRepo.getPostsByContent]
|
|
*/
|
|
@Serializable
|
|
data class RegisteredContent(
|
|
val id: ContentId,
|
|
val content: Content
|
|
)
|