diff --git a/core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/api/ReadContentAPI.kt b/core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/api/ReadContentAPI.kt index 1e91afe2..7219b59b 100644 --- a/core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/api/ReadContentAPI.kt +++ b/core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/api/ReadContentAPI.kt @@ -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 /** * @return [RegisteredContent] if it is available by [id] */ diff --git a/core/src/commonTest/kotlin/com/insanusmokrassar/postssystem/core/api/InMemoryContentAPI.kt b/core/src/commonTest/kotlin/com/insanusmokrassar/postssystem/core/api/InMemoryContentAPI.kt index 87e7fb82..235808da 100644 --- a/core/src/commonTest/kotlin/com/insanusmokrassar/postssystem/core/api/InMemoryContentAPI.kt +++ b/core/src/commonTest/kotlin/com/insanusmokrassar/postssystem/core/api/InMemoryContentAPI.kt @@ -37,6 +37,8 @@ class InMemoryContentAPI( } } + override suspend fun getContentsIds(): Set = contents.keys.toSet() + override suspend fun getContentById(id: ContentId): RegisteredContent? = contents[id] override suspend fun getContentByPagination(pagination: Pagination): PaginationResult { diff --git a/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt b/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt index e9d158b6..08a684ee 100644 --- a/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt +++ b/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt @@ -64,6 +64,11 @@ private class ContentAPIDatabaseTable( Json.plain.parse(Content.serializer(), get(dataColumn)) ) + override suspend fun getContentsIds(): Set { + return transaction { + selectAll().map { it[idColumn] } + }.toSet() + } override suspend fun getContentById(id: ContentId): RegisteredContent? { return transaction { select { idColumn.eq(id) }.firstOrNull() ?.asRegisteredContent()