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
|
2020-08-11 16:15:07 +00:00
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
import kotlinx.serialization.Transient
|
2019-09-20 07:01:32 +00:00
|
|
|
|
|
|
|
typealias PostId = String
|
2019-11-04 07:33:03 +00:00
|
|
|
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
|
|
|
|
*/
|
2020-08-11 16:15:07 +00:00
|
|
|
@Serializable
|
|
|
|
sealed class Post {
|
|
|
|
abstract val content: ContentIds
|
2019-10-19 10:58:49 +00:00
|
|
|
}
|
|
|
|
|
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]
|
2020-08-11 16:15:07 +00:00
|
|
|
* instance
|
2019-11-01 05:27:58 +00:00
|
|
|
*/
|
2020-08-11 16:15:07 +00:00
|
|
|
@Serializable
|
|
|
|
sealed class RegisteredPost : Post() {
|
|
|
|
abstract val id: PostId
|
2019-10-19 10:58:49 +00:00
|
|
|
|
2020-08-11 16:15:07 +00:00
|
|
|
abstract override val content: ContentIds
|
2019-09-20 07:05:14 +00:00
|
|
|
|
2020-08-11 16:15:07 +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
|
|
|
|
*/
|
2020-08-11 16:15:07 +00:00
|
|
|
@Serializable
|
2019-10-17 11:35:48 +00:00
|
|
|
data class SimplePost(
|
2019-11-04 07:33:03 +00:00
|
|
|
override val content: ContentIds
|
2020-08-11 16:15:07 +00:00
|
|
|
) : Post()
|
2019-10-19 10:58:49 +00:00
|
|
|
|
2019-11-01 05:27:58 +00:00
|
|
|
/**
|
|
|
|
* Base and currently (1st Nov 2019) single realisation of [RegisteredPost]
|
|
|
|
*/
|
2020-08-11 16:15:07 +00:00
|
|
|
@Serializable
|
2019-10-19 10:58:49 +00:00
|
|
|
data class SimpleRegisteredPost(
|
|
|
|
override val id: PostId,
|
2019-11-04 07:33:03 +00:00
|
|
|
override val content: ContentIds,
|
2020-08-11 16:15:07 +00:00
|
|
|
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)
|