improve hierachi of classes for contents and posts

This commit is contained in:
2019-10-19 16:58:49 +06:00
parent 16311b8f1c
commit 0c98fe3dfb
11 changed files with 73 additions and 62 deletions

View File

@@ -1,17 +1,16 @@
package com.insanusmokrassar.postssystem.core.api
import com.insanusmokrassar.postssystem.core.post.Post
import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.content.ContentId
import com.insanusmokrassar.postssystem.core.post.*
import com.insanusmokrassar.postssystem.core.utils.pagination.*
import com.insanusmokrassar.postssystem.core.utils.pagination.Pagination
import com.insanusmokrassar.postssystem.core.utils.pagination.PaginationResult
import org.joda.time.DateTime
interface ReadPostsAPI {
suspend fun getPostById(id: PostId): Post?
suspend fun getPostsByContent(id: ContentId): List<Post>
suspend fun getPostsByDates(from: DateTime? = null, to: DateTime? = null): List<Post>
suspend fun getPostById(id: PostId): RegisteredPost?
suspend fun getPostsByContent(id: ContentId): List<RegisteredPost>
suspend fun getPostsByDates(from: DateTime? = null, to: DateTime? = null): List<RegisteredPost>
suspend fun getPostsByPagination(pagination: Pagination): PaginationResult<out Post>
suspend fun getPostsByPagination(pagination: Pagination): PaginationResult<out RegisteredPost>
}

View File

@@ -5,12 +5,12 @@ import com.insanusmokrassar.postssystem.core.post.*
import kotlinx.coroutines.flow.Flow
interface WritePostsAPI {
val postCreatedFlow: Flow<Post>
val postDeletedFlow: Flow<Post>
val postUpdatedFlow: Flow<Post>
val postCreatedFlow: Flow<RegisteredPost>
val postDeletedFlow: Flow<RegisteredPost>
val postUpdatedFlow: Flow<RegisteredPost>
suspend fun createPost(content: PostContents): Post?
suspend fun createPost(post: Post): RegisteredPost?
suspend fun deletePost(id: PostId): Boolean
suspend fun updatePostContent(postId: PostId, content: PostContents): Boolean
suspend fun updatePostContent(postId: PostId, post: Post): Boolean
}

View File

@@ -2,6 +2,8 @@ package com.insanusmokrassar.postssystem.core.content
typealias ContentId = String
interface Content {
interface Content
interface RegisteredContent : Content {
val id: ContentId
}

View File

@@ -1,5 +1,20 @@
package com.insanusmokrassar.postssystem.core.content
import kotlinx.serialization.Serializable
interface TextContent : Content {
val text: String
}
}
interface TextRegisteredContent : RegisteredContent, TextContent
@Serializable
data class SimpleTextContent(
override val text: String
) : TextContent
@Serializable
data class SimpleTextRegisteredContent(
override val id: ContentId,
override val text: String
) : TextRegisteredContent

View File

@@ -1,21 +1,36 @@
package com.insanusmokrassar.postssystem.core.post
import com.insanusmokrassar.postssystem.core.content.Content
import com.insanusmokrassar.postssystem.core.content.RegisteredContent
import kotlinx.serialization.Serializable
import org.joda.time.DateTime
typealias PostId = String
typealias PostContents = List<Content>
typealias RegisteredPostContents = List<RegisteredContent>
interface Post {
val id: PostId
val content: PostContents
}
val meta: PostMetaInfo
interface RegisteredPost : Post {
val id: PostId
override val content: RegisteredPostContents
val creationDate: DateTime
val modificationDate: DateTime
}
@Serializable
data class SimplePost(
override val id: PostId,
override val content: PostContents,
override val meta: PostMetaInfo
override val content: PostContents
) : Post
@Serializable
data class SimpleRegisteredPost(
override val id: PostId,
override val content: RegisteredPostContents,
override val creationDate: DateTime,
override val modificationDate: DateTime = creationDate
) : RegisteredPost

View File

@@ -1,9 +0,0 @@
package com.insanusmokrassar.postssystem.core.post
import org.joda.time.DateTime
interface PostMetaInfo {
val postId: PostId
val creationDate: DateTime
val modificationDate: DateTime
}