core/core/api/src/commonMain/kotlin/dev/inmo/postssystem/core/post/Post.kt

61 lines
1.7 KiB
Kotlin
Raw Normal View History

2020-11-25 08:08:45 +00:00
package dev.inmo.postssystem.core.post
2019-09-20 07:01:32 +00:00
2020-11-25 08:08:45 +00:00
import dev.inmo.postssystem.core.UnixMillis
import dev.inmo.postssystem.core.content.ContentId
2019-11-05 05:26:42 +00:00
import com.soywiz.klock.DateTime
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
2019-09-20 07:01:32 +00:00
typealias PostId = String
typealias ContentIds = List<ContentId>
2019-09-20 07:01:32 +00:00
2019-11-01 05:27:58 +00:00
/**
* Base interface for creating of new post. Usually, it is just [SimplePost] instance
*/
@Serializable
sealed class Post {
abstract val content: ContentIds
}
2019-11-01 05:27:58 +00:00
/**
2020-11-25 08:08:45 +00:00
* Root entity of the whole system. Can be retrieved from [dev.inmo.postssystem.core.post.repo.ReadPostsRepo]
* by getting and created in [dev.inmo.postssystem.core.post.repo.WritePostsRepo] by inserting of [Post]
* instance
2019-11-01 05:27:58 +00:00
*/
@Serializable
sealed class RegisteredPost : Post() {
abstract val id: PostId
abstract override val content: ContentIds
2019-09-20 07:05:14 +00:00
abstract val creationDate: DateTime
2019-10-17 11:35:48 +00:00
}
2019-11-01 05:27:58 +00:00
/**
* Base and currently (1st Nov 2019) single realisation of [Post]. There is [SimpleRegisteredPost] which is technically
* is [Post] too, but it is not direct [Post] realisation
*/
@Serializable
2019-10-17 11:35:48 +00:00
data class SimplePost(
override val content: ContentIds
) : Post()
2019-11-01 05:27:58 +00:00
/**
* Base and currently (1st Nov 2019) single realisation of [RegisteredPost]
*/
@Serializable
data class SimpleRegisteredPost(
override val id: PostId,
override val content: ContentIds,
private val creationDateTimeMillis: UnixMillis
) : RegisteredPost() {
@Transient
override val creationDate: DateTime = DateTime(creationDateTimeMillis)
}
@Suppress("FunctionName")
fun RegisteredPost(
id: PostId,
content: ContentIds,
creationDate: DateTime
) = SimpleRegisteredPost(id, content, creationDate.unixMillis)