add method "getContentsIds"

This commit is contained in:
InsanusMokrassar 2019-11-11 00:20:55 +06:00
parent 4e3e59435b
commit 1328a0c84d
3 changed files with 11 additions and 0 deletions

View File

@ -9,6 +9,10 @@ import com.insanusmokrassar.postssystem.core.utils.pagination.PaginationResult
* Simple read API by different properties of [com.insanusmokrassar.postssystem.core.content.Content].
*/
interface ReadContentAPI {
/**
* @return [Set] of [ContentId] wich currently known in this instance of API
*/
suspend fun getContentsIds(): Set<ContentId>
/**
* @return [RegisteredContent] if it is available by [id]
*/

View File

@ -37,6 +37,8 @@ class InMemoryContentAPI(
}
}
override suspend fun getContentsIds(): Set<ContentId> = contents.keys.toSet()
override suspend fun getContentById(id: ContentId): RegisteredContent? = contents[id]
override suspend fun getContentByPagination(pagination: Pagination): PaginationResult<out RegisteredContent> {

View File

@ -64,6 +64,11 @@ private class ContentAPIDatabaseTable(
Json.plain.parse(Content.serializer(), get(dataColumn))
)
override suspend fun getContentsIds(): Set<ContentId> {
return transaction {
selectAll().map { it[idColumn] }
}.toSet()
}
override suspend fun getContentById(id: ContentId): RegisteredContent? {
return transaction {
select { idColumn.eq(id) }.firstOrNull() ?.asRegisteredContent()