Skip to content

Commit

Permalink
πŸ”€ #89 from boostcampwm-2022/feat/running_tab
Browse files Browse the repository at this point in the history
♻️ λ¬Έμžμ—΄ μƒμˆ˜λ‘œ λ³€κ²½, μ·¨μ†Œ κ°€λŠ₯ν•œ μ„œμŠ€νŽœλ“œ λ³€κ²½
  • Loading branch information
yonghanJu authored Dec 9, 2022
2 parents a26b243 + 444ca57 commit 8ab338a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int> = callbackFlow {
db.collection(CollectionId.RUNNERS_COLLECTION)
.document("runnersId")
.document(CollectionId.RUNNERS_ID)
.addSnapshotListener { snapshot, _ ->
snapshot?.let {
val count = it.data?.size ?: -1
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8ab338a

Please sign in to comment.