Skip to content

Commit 0b04b79

Browse files
authored
πŸ”€ #57 from boostcampwm-2022/feat/running_tab
λŸ¬λ‹ ν™”λ©΄ κ°œμ„  및 λŸ¬λ‹ μ’…λ£Œ ν™”λ©΄ κ΅¬ν˜„
2 parents 7644175 + 5b1a340 commit 0b04b79

36 files changed

+876
-170
lines changed

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryDao.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.room.Dao
44
import androidx.room.Insert
55
import androidx.room.OnConflictStrategy
66
import androidx.room.Query
7+
import com.whyranoid.data.model.RunningHistoryEntity
78
import kotlinx.coroutines.flow.Flow
89

910
@Dao

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryLocalDataBase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.whyranoid.data.account
22

33
import androidx.room.Database
44
import androidx.room.RoomDatabase
5+
import com.whyranoid.data.model.RunningHistoryEntity
56

67
@Database(
78
entities = [RunningHistoryEntity::class],
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.whyranoid.data.account
22

3+
import com.whyranoid.data.model.RunningHistoryEntity
34
import com.whyranoid.domain.model.RunningHistory
45
import kotlinx.coroutines.flow.Flow
56

67
interface RunningHistoryLocalDataSource {
78
fun getRunningHistory(): Flow<Result<List<RunningHistory>>>
9+
suspend fun saveRunningHistory(runningHistoryEntity: RunningHistoryEntity): Result<RunningHistory>
810
}

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryLocalDataSourceImpl.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.whyranoid.data.account
22

3+
import com.whyranoid.data.model.RunningHistoryEntity
4+
import com.whyranoid.data.model.toRunningHistory
35
import com.whyranoid.domain.model.RunningHistory
46
import kotlinx.coroutines.flow.Flow
57
import kotlinx.coroutines.flow.map
@@ -18,4 +20,11 @@ class RunningHistoryLocalDataSourceImpl @Inject constructor(
1820
}
1921
}
2022
}
23+
24+
override suspend fun saveRunningHistory(runningHistoryEntity: RunningHistoryEntity): Result<RunningHistory> {
25+
return kotlin.runCatching {
26+
runningHistoryDao.addRunningHistory(runningHistoryEntity)
27+
runningHistoryEntity.toRunningHistory()
28+
}
29+
}
2130
}

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryRepositoryImpl.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.whyranoid.data.account
22

3+
import com.whyranoid.data.model.RunningHistoryEntity
34
import com.whyranoid.domain.model.RunningHistory
45
import com.whyranoid.domain.repository.RunningHistoryRepository
56
import kotlinx.coroutines.flow.Flow
@@ -17,12 +18,22 @@ class RunningHistoryRepositoryImpl @Inject constructor(
1718
}
1819

1920
override suspend fun saveRunningHistory(
21+
historyId: String,
2022
startedAt: Long,
2123
finishedAt: Long,
2224
totalRunningTime: Int,
2325
pace: Double,
2426
totalDistance: Double
2527
): Result<RunningHistory> {
26-
TODO("Not yet implemented")
28+
return runningHistoryLocalDataSource.saveRunningHistory(
29+
RunningHistoryEntity(
30+
historyId = historyId,
31+
startedAt = startedAt,
32+
finishedAt = finishedAt,
33+
totalRunningTime = totalRunningTime,
34+
pace = pace,
35+
totalDistance = totalDistance
36+
)
37+
)
2738
}
2839
}

β€Ždata/src/main/java/com/whyranoid/data/group/GroupRepositoryImpl.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.whyranoid.data.user.UserDataSource
55
import com.whyranoid.domain.model.GroupInfo
66
import com.whyranoid.domain.model.GroupNotification
77
import com.whyranoid.domain.model.Rule
8+
import com.whyranoid.domain.model.RunningHistory
89
import com.whyranoid.domain.repository.GroupRepository
910
import kotlinx.coroutines.flow.Flow
1011
import javax.inject.Inject
@@ -50,6 +51,14 @@ class GroupRepositoryImpl @Inject constructor(
5051
groupNotificationDataSource.notifyRunningStart(uid, groupIdList)
5152
}
5253

54+
override suspend fun notifyRunningFinish(
55+
uid: String,
56+
runningHistory: RunningHistory,
57+
groupIdList: List<String>
58+
) {
59+
groupNotificationDataSource.notifyRunningFinish(uid, runningHistory, groupIdList)
60+
}
61+
5362
override suspend fun createGroup(
5463
groupName: String,
5564
introduce: String,

β€Ždata/src/main/java/com/whyranoid/data/groupnotification/GroupNotificationDataSource.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ class GroupNotificationDataSource @Inject constructor(
7373
}
7474
}
7575

76+
suspend fun notifyRunningFinish(
77+
uid: String,
78+
runningHistory: RunningHistory,
79+
groupIdList: List<String>
80+
) {
81+
withContext(Dispatchers.IO) {
82+
groupIdList.forEach { groupId ->
83+
db.collection(GROUP_NOTIFICATIONS_COLLECTION)
84+
.document(groupId)
85+
.collection(FINISH_NOTIFICATION)
86+
.document(UUID.randomUUID().toString())
87+
.set(
88+
FinishNotificationResponse(
89+
type = "finish",
90+
uid = uid,
91+
historyId = runningHistory.historyId
92+
)
93+
)
94+
}
95+
}
96+
}
97+
7698
private fun getGroupFinishNotifications(groupId: String): Flow<List<GroupNotification>> =
7799
callbackFlow {
78100
db.collection(GROUP_NOTIFICATIONS_COLLECTION)

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryEntity.kt renamed to β€Ždata/src/main/java/com/whyranoid/data/model/RunningHistoryEntity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.whyranoid.data.account
1+
package com.whyranoid.data.model
22

33
import androidx.room.ColumnInfo
44
import androidx.room.Entity

β€Ždata/src/main/java/com/whyranoid/data/running/RunnerDataSourceImpl.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.whyranoid.data.running
22

33
import com.google.firebase.firestore.FieldValue
44
import com.google.firebase.firestore.FirebaseFirestore
5+
import com.whyranoid.data.constant.CollectionId
56
import kotlinx.coroutines.channels.awaitClose
67
import kotlinx.coroutines.flow.Flow
78
import kotlinx.coroutines.flow.callbackFlow
@@ -11,7 +12,7 @@ import kotlin.coroutines.suspendCoroutine
1112
class RunnerDataSourceImpl(private val db: FirebaseFirestore) : RunnerDataSource {
1213

1314
override fun getCurrentRunnerCount(): Flow<Int> = callbackFlow {
14-
db.collection("Runners")
15+
db.collection(CollectionId.RUNNERS_COLLECTION)
1516
.document("runnersId")
1617
.addSnapshotListener { snapshot, _ ->
1718
snapshot?.let {
@@ -24,8 +25,9 @@ class RunnerDataSourceImpl(private val db: FirebaseFirestore) : RunnerDataSource
2425
}
2526

2627
override suspend fun startRunning(uid: String): Boolean {
28+
if (uid.isBlank()) return false
2729
return suspendCoroutine { continuation ->
28-
db.collection("Runners")
30+
db.collection(CollectionId.RUNNERS_COLLECTION)
2931
.document("runnersId")
3032
.update(uid, uid)
3133
.addOnSuccessListener {
@@ -38,9 +40,9 @@ class RunnerDataSourceImpl(private val db: FirebaseFirestore) : RunnerDataSource
3840
}
3941

4042
override suspend fun finishRunning(uid: String): Boolean {
41-
// TODO κ΅¬ν˜„
43+
if (uid.isBlank()) return false
4244
return suspendCoroutine { continuation ->
43-
db.collection("Runners")
45+
db.collection(CollectionId.RUNNERS_COLLECTION)
4446
.document("runnersId")
4547
.update(uid, FieldValue.delete())
4648
.addOnSuccessListener {

β€Ždata/src/main/java/com/whyranoid/data/running/RunnerRepositoryImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class RunnerRepositoryImpl(private val runnerDataSource: RunnerDataSource) : Run
1313
}
1414

1515
override suspend fun finishRunning(uid: String): Boolean {
16-
return true
16+
return runnerDataSource.finishRunning(uid)
1717
}
1818
}

0 commit comments

Comments
Β (0)