File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
data/src/main/java/com/whyranoid/data Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.whyranoid.data.account
2
+
3
+ import com.whyranoid.domain.model.RunningHistory
4
+
5
+ interface RunningHistoryRemoteDataSource {
6
+
7
+ suspend fun uploadRunningHistory (runningHistory : RunningHistory ): Result <Boolean >
8
+ }
Original file line number Diff line number Diff line change
1
+ package com.whyranoid.data.account
2
+
3
+ import com.google.firebase.firestore.FirebaseFirestore
4
+ import com.whyranoid.data.constant.CollectionId
5
+ import com.whyranoid.data.model.toRunningHistoryResponse
6
+ import com.whyranoid.domain.model.RunningHistory
7
+ import kotlinx.coroutines.Dispatchers
8
+ import kotlinx.coroutines.tasks.await
9
+ import kotlinx.coroutines.withContext
10
+ import javax.inject.Inject
11
+
12
+ class RunningHistoryRemoteDataSourceImpl @Inject constructor(private val firebaseDB : FirebaseFirestore ) :
13
+ RunningHistoryRemoteDataSource {
14
+ override suspend fun uploadRunningHistory (runningHistory : RunningHistory ): Result <Boolean > {
15
+ val runningHistoryResponse = runningHistory.toRunningHistoryResponse()
16
+ var uploadSuccess = false
17
+
18
+ return runCatching {
19
+ withContext(Dispatchers .IO ) {
20
+ val task = firebaseDB.collection(CollectionId .RUNNING_HISTORY_COLLECTION )
21
+ .document(runningHistoryResponse.historyId)
22
+ .set(runningHistoryResponse)
23
+ .addOnSuccessListener {
24
+ uploadSuccess = true
25
+ }
26
+ .addOnFailureListener { exception ->
27
+ throw exception
28
+ }
29
+
30
+ task.await()
31
+ }
32
+ uploadSuccess
33
+ }
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ package com.whyranoid.data.model
2
+
3
+ import com.whyranoid.domain.model.RunningHistory
4
+
5
+ data class RunningHistoryResponse (
6
+ val historyId : String = " " ,
7
+ val startedAt : Long = 0L ,
8
+ val finishedAt : Long = 0L ,
9
+ val totalRunningTime : Int = 0 ,
10
+ val pace : Double = 0.0 ,
11
+ val totalDistance : Double = 0.0
12
+ )
13
+
14
+ fun RunningHistory.toRunningHistoryResponse () =
15
+ RunningHistoryResponse (
16
+ historyId = historyId,
17
+ startedAt = startedAt,
18
+ finishedAt = finishedAt,
19
+ totalRunningTime = totalRunningTime,
20
+ pace = pace,
21
+ totalDistance = totalDistance
22
+ )
You can’t perform that action at this time.
0 commit comments