Skip to content

Commit 0f32079

Browse files
committed
✨ 운동 종료 알림 데이터 형식 변경 및 그에 따른 DataSource 수정
1 parent 1948d6a commit 0f32079

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

data/src/main/java/com/whyranoid/data/constant/CollectionId.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ object CollectionId {
99
const val START_NOTIFICATION = "start"
1010
const val FINISH_NOTIFICATION = "finish"
1111
const val POST_COLLECTION = "Posts"
12+
const val RUNNING_HISTORY_COLLECTION = "RunningHistory"
1213
}

data/src/main/java/com/whyranoid/data/groupnotification/GroupNotificationDataSource.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package com.whyranoid.data.groupnotification
33
import com.google.firebase.firestore.FirebaseFirestore
44
import com.whyranoid.data.constant.CollectionId.FINISH_NOTIFICATION
55
import com.whyranoid.data.constant.CollectionId.GROUP_NOTIFICATIONS_COLLECTION
6+
import com.whyranoid.data.constant.CollectionId.RUNNING_HISTORY_COLLECTION
67
import com.whyranoid.data.constant.CollectionId.START_NOTIFICATION
78
import com.whyranoid.data.model.FinishNotificationResponse
89
import com.whyranoid.data.model.StartNotificationResponse
9-
import com.whyranoid.data.model.toFinishNotification
1010
import com.whyranoid.data.model.toStartNotification
11+
import com.whyranoid.domain.model.FinishNotification
1112
import com.whyranoid.domain.model.GroupNotification
13+
import com.whyranoid.domain.model.RunningHistory
1214
import com.whyranoid.domain.model.StartNotification
1315
import kotlinx.coroutines.Dispatchers
1416
import kotlinx.coroutines.FlowPreview
@@ -79,9 +81,26 @@ class GroupNotificationDataSource @Inject constructor(
7981
.addSnapshotListener { snapshot, error ->
8082
val finishNotificationList = mutableListOf<GroupNotification>()
8183
snapshot?.forEach { document ->
82-
val finishNotification =
84+
val finishNotificationResponse =
8385
document.toObject(FinishNotificationResponse::class.java)
84-
finishNotificationList.add(finishNotification.toFinishNotification())
86+
87+
finishNotificationResponse.let { finishNotificationResponse ->
88+
db.collection(RUNNING_HISTORY_COLLECTION)
89+
.document(finishNotificationResponse.historyId)
90+
.get()
91+
.addOnSuccessListener {
92+
val runningHistory = it.toObject(RunningHistory::class.java)
93+
94+
runningHistory?.let {
95+
finishNotificationList.add(
96+
FinishNotification(
97+
uid = finishNotificationResponse.uid,
98+
runningHistory = runningHistory
99+
)
100+
)
101+
}
102+
}
103+
}
85104
}
86105
trySend(finishNotificationList)
87106
}
Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.whyranoid.data.model
22

3-
import com.whyranoid.domain.model.FinishNotification
4-
import com.whyranoid.domain.model.RunningHistory
53
import com.whyranoid.domain.model.StartNotification
64

75
sealed interface GroupNotificationResponse {
@@ -18,29 +16,11 @@ data class StartNotificationResponse(
1816
data class FinishNotificationResponse(
1917
override val type: String = "",
2018
override val uid: String = "",
21-
val finishedAt: Long = 0L,
22-
val historyId: String = "",
23-
val pace: Double = 0.0,
24-
val startedAt: Long = 0L,
25-
val totalDistance: Double = 0.0,
26-
val totalRunningTime: Int = 0
19+
val historyId: String = ""
2720
) : GroupNotificationResponse
2821

2922
fun StartNotificationResponse.toStartNotification() =
3023
StartNotification(
3124
uid = this.uid,
3225
startedAt = this.startedAt
3326
)
34-
35-
fun FinishNotificationResponse.toFinishNotification() =
36-
FinishNotification(
37-
uid = this.uid,
38-
runningHistory = RunningHistory(
39-
historyId = this.historyId,
40-
startedAt = this.startedAt,
41-
finishedAt = this.finishedAt,
42-
totalRunningTime = this.totalRunningTime,
43-
pace = this.pace,
44-
totalDistance = this.totalDistance
45-
)
46-
)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.whyranoid.domain.model
22

33
data class RunningHistory(
4-
val historyId: String,
5-
val startedAt: Long,
6-
val finishedAt: Long,
7-
val totalRunningTime: Int,
8-
val pace: Double,
9-
val totalDistance: Double
4+
val historyId: String = "",
5+
val startedAt: Long = 0L,
6+
val finishedAt: Long = 0L,
7+
val totalRunningTime: Int = 0,
8+
val pace: Double = 0.0,
9+
val totalDistance: Double = 0.0
1010
)

0 commit comments

Comments
 (0)