From 1328a0c84d459aad165ab580c025dd455d0c7567 Mon Sep 17 00:00:00 2001
From: InsanusMokrassar <ovsyannikov.alexey95@gmail.com>
Date: Mon, 11 Nov 2019 00:20:55 +0600
Subject: [PATCH] add method "getContentsIds"

---
 .../postssystem/core/content/api/ReadContentAPI.kt           | 4 ++++
 .../postssystem/core/api/InMemoryContentAPI.kt               | 2 ++
 .../postssystem/core/exposed/ExposedContentAPI.kt            | 5 +++++
 3 files changed, 11 insertions(+)

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<ContentId>
     /**
      * @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<ContentId> = contents.keys.toSet()
+
     override suspend fun getContentById(id: ContentId): RegisteredContent? = contents[id]
 
     override suspend fun getContentByPagination(pagination: Pagination): PaginationResult<out RegisteredContent> {
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<ContentId> {
+        return transaction {
+            selectAll().map { it[idColumn] }
+        }.toSet()
+    }
     override suspend fun getContentById(id: ContentId): RegisteredContent? {
         return transaction {
             select { idColumn.eq(id) }.firstOrNull() ?.asRegisteredContent()