From 444ca5705fa0a56e7c7a8bebbc3d1a96c4fd381e Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Thu, 8 Dec 2022 23:52:10 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EC=83=81=EC=88=98=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C=20=EA=B0=80=EB=8A=A5=ED=95=9C=20=EC=84=9C=EC=8A=A4?= =?UTF-8?q?=ED=8E=9C=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/whyranoid/data/constant/CollectionId.kt | 1 + .../whyranoid/data/running/RunnerDataSourceImpl.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/data/src/main/java/com/whyranoid/data/constant/CollectionId.kt b/data/src/main/java/com/whyranoid/data/constant/CollectionId.kt index 13fa1b2e..ad1a40e0 100644 --- a/data/src/main/java/com/whyranoid/data/constant/CollectionId.kt +++ b/data/src/main/java/com/whyranoid/data/constant/CollectionId.kt @@ -4,6 +4,7 @@ object CollectionId { const val USERS_COLLECTION = "Users" const val RUNNERS_COLLECTION = "Runners" + const val RUNNERS_ID = "runnersId" const val GROUPS_COLLECTION = "Groups" const val GROUP_NOTIFICATIONS_COLLECTION = "GroupNotifications" const val START_NOTIFICATION = "start" diff --git a/data/src/main/java/com/whyranoid/data/running/RunnerDataSourceImpl.kt b/data/src/main/java/com/whyranoid/data/running/RunnerDataSourceImpl.kt index 8b2a46e1..b61a34d6 100644 --- a/data/src/main/java/com/whyranoid/data/running/RunnerDataSourceImpl.kt +++ b/data/src/main/java/com/whyranoid/data/running/RunnerDataSourceImpl.kt @@ -6,14 +6,14 @@ import com.whyranoid.data.constant.CollectionId import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow +import kotlinx.coroutines.suspendCancellableCoroutine import kotlin.coroutines.resume -import kotlin.coroutines.suspendCoroutine class RunnerDataSourceImpl(private val db: FirebaseFirestore) : RunnerDataSource { override fun getCurrentRunnerCount(): Flow = callbackFlow { db.collection(CollectionId.RUNNERS_COLLECTION) - .document("runnersId") + .document(CollectionId.RUNNERS_ID) .addSnapshotListener { snapshot, _ -> snapshot?.let { val count = it.data?.size ?: -1 @@ -26,9 +26,9 @@ class RunnerDataSourceImpl(private val db: FirebaseFirestore) : RunnerDataSource override suspend fun startRunning(uid: String): Boolean { if (uid.isBlank()) return false - return suspendCoroutine { continuation -> + return suspendCancellableCoroutine { continuation -> db.collection(CollectionId.RUNNERS_COLLECTION) - .document("runnersId") + .document(CollectionId.RUNNERS_ID) .update(uid, uid) .addOnSuccessListener { continuation.resume(true) @@ -41,9 +41,9 @@ class RunnerDataSourceImpl(private val db: FirebaseFirestore) : RunnerDataSource override suspend fun finishRunning(uid: String): Boolean { if (uid.isBlank()) return false - return suspendCoroutine { continuation -> + return suspendCancellableCoroutine { continuation -> db.collection(CollectionId.RUNNERS_COLLECTION) - .document("runnersId") + .document(CollectionId.RUNNERS_ID) .update(uid, FieldValue.delete()) .addOnSuccessListener { continuation.resume(true)