add method "getContentsIds"
This commit is contained in:
parent
4e3e59435b
commit
1328a0c84d
@ -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]
|
||||
*/
|
||||
|
@ -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> {
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user