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

@@ -20,20 +20,20 @@ class ReadableHttpPostsAPI(
private val postsByDatesAddress = "$baseAddress/$getPostsByDatesAddress"
private val postsByPaginationAddress = "$baseAddress/$getPostsByPaginationAddress"
override suspend fun getPostById(id: PostId): Post? {
return client.post<SimplePost>(postByIdAddress) {
override suspend fun getPostById(id: PostId): RegisteredPost? {
return client.post<SimpleRegisteredPost>(postByIdAddress) {
body = id
}
}
override suspend fun getPostsByContent(id: ContentId): List<Post> {
return client.post<List<SimplePost>>(postsByContentIdAddress) {
override suspend fun getPostsByContent(id: ContentId): List<RegisteredPost> {
return client.post<List<SimpleRegisteredPost>>(postsByContentIdAddress) {
body = id
}
}
override suspend fun getPostsByDates(from: DateTime?, to: DateTime?): List<Post> {
return client.post<List<SimplePost>>(postsByDatesAddress) {
override suspend fun getPostsByDates(from: DateTime?, to: DateTime?): List<RegisteredPost> {
return client.post<List<SimpleRegisteredPost>>(postsByDatesAddress) {
body = DateTimeRequest(
from ?.millis,
to ?.millis
@@ -41,8 +41,8 @@ class ReadableHttpPostsAPI(
}
}
override suspend fun getPostsByPagination(pagination: Pagination): PaginationResult<out Post> {
return client.post<PaginationResult<SimplePost>>(postsByPaginationAddress) {
override suspend fun getPostsByPagination(pagination: Pagination): PaginationResult<out RegisteredPost> {
return client.post<PaginationResult<SimpleRegisteredPost>>(postsByPaginationAddress) {
body = pagination
}
}

View File

@@ -20,17 +20,17 @@ class WritableHttpPostsAPI(
port,
"/$url"
) {
Json.plain.parse(SimplePost.serializer(), it)
Json.plain.parse(SimpleRegisteredPost.serializer(), it)
}
override val postCreatedFlow: Flow<Post> = postEventFlow(eventPostsCreatedAddress)
override val postDeletedFlow: Flow<Post> = postEventFlow(eventPostsDeletedAddress)
override val postUpdatedFlow: Flow<Post> = postEventFlow(eventPostsUpdatedAddress)
override val postCreatedFlow: Flow<RegisteredPost> = postEventFlow(eventPostsCreatedAddress)
override val postDeletedFlow: Flow<RegisteredPost> = postEventFlow(eventPostsDeletedAddress)
override val postUpdatedFlow: Flow<RegisteredPost> = postEventFlow(eventPostsUpdatedAddress)
override suspend fun createPost(content: PostContents): Post? = client.post<SimplePost>(
override suspend fun createPost(post: Post): RegisteredPost? = client.post<SimpleRegisteredPost>(
createPostAddress
) {
body = content
body = post.content
}
override suspend fun deletePost(id: PostId): Boolean = client.post(deletePostAddress) {
@@ -39,8 +39,8 @@ class WritableHttpPostsAPI(
override suspend fun updatePostContent(
postId: PostId,
content: PostContents
post: Post
): Boolean = client.post(createPostAddress) {
body = UpdatePostRequest(postId, content)
body = UpdatePostRequest(postId, post.content)
}
}