add getting of posts by page

This commit is contained in:
InsanusMokrassar 2019-09-20 13:19:03 +06:00
parent 2d5189ce0a
commit 9c1bffab41
4 changed files with 32 additions and 0 deletions

View File

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

View File

@ -0,0 +1,6 @@
package com.github.insanusmokrassar.postssystem.core.utils.pagination
interface Pagination {
val page: Int
val size: Int
}

View File

@ -0,0 +1,9 @@
package com.github.insanusmokrassar.postssystem.core.utils.pagination
import kotlinx.serialization.Serializable
@Serializable
data class PaginationRequest(
override val page: Int,
override val size: Int
) : Pagination

View File

@ -0,0 +1,14 @@
package com.github.insanusmokrassar.postssystem.core.utils.pagination
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable
data class PaginationResult<T>(
override val page: Int,
val pagesNumber: Int,
val results: List<T>
) : Pagination {
@Transient
override val size: Int = results.size
}