54 lines
1.6 KiB
Kotlin
54 lines
1.6 KiB
Kotlin
package dev.inmo.postssystem.core.post.repo
|
|
|
|
import dev.inmo.postssystem.core.MAX_DATE
|
|
import dev.inmo.postssystem.core.MIN_DATE
|
|
import dev.inmo.postssystem.core.content.ContentId
|
|
import dev.inmo.postssystem.core.post.PostId
|
|
import dev.inmo.postssystem.core.post.RegisteredPost
|
|
import com.soywiz.klock.DateTime
|
|
import dev.inmo.micro_utils.pagination.*
|
|
|
|
/**
|
|
* Simple read API by different properties
|
|
*/
|
|
interface ReadPostsRepo {
|
|
/**
|
|
* @return [Set] of [PostId]s which can be used to get data using [getPostById]
|
|
*/
|
|
suspend fun getPostsIds(): Set<PostId>
|
|
|
|
/**
|
|
* @return [RegisteredPost] if it is available by [id]
|
|
*/
|
|
suspend fun getPostById(id: PostId): RegisteredPost?
|
|
|
|
/**
|
|
* @return all [RegisteredPost]s which contains content with specified content [id]
|
|
*/
|
|
suspend fun getPostsByContent(id: ContentId): List<RegisteredPost>
|
|
|
|
/**
|
|
* @return all [RegisteredPost]s which was registered between [from] and [to]. Range will be used INCLUSIVE, line \[[from], [to]\]
|
|
*/
|
|
suspend fun getPostsByCreatingDates(
|
|
from: DateTime = MIN_DATE,
|
|
to: DateTime = MAX_DATE,
|
|
pagination: Pagination = FirstPagePagination()
|
|
): PaginationResult<RegisteredPost>
|
|
|
|
/**
|
|
* @return all posts by pages basing on their creation date
|
|
*/
|
|
suspend fun getPostsByPagination(pagination: Pagination): PaginationResult<RegisteredPost>
|
|
}
|
|
|
|
suspend fun ReadPostsRepo.getPostsByCreatingDates(
|
|
from: DateTime? = null,
|
|
to: DateTime? = null,
|
|
pagination: Pagination = FirstPagePagination()
|
|
) = getPostsByCreatingDates(
|
|
from ?: MIN_DATE,
|
|
to ?: MAX_DATE,
|
|
pagination
|
|
)
|