Skip to content

Commit 64b9ae8

Browse files
yonghanJubngsh
authored andcommitted
✨ RunningHistory 저장하기 data layer 모듈 구현
1 parent c2d25eb commit 64b9ae8

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed
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
}

domain/src/main/java/com/whyranoid/domain/repository/RunningHistoryRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface RunningHistoryRepository {
1313

1414
// 운동한 기록 저장하기 - 로컬
1515
suspend fun saveRunningHistory(
16+
historyId: String,
1617
startedAt: Long,
1718
finishedAt: Long,
1819
totalRunningTime: Int,

domain/src/main/java/com/whyranoid/domain/usecase/SaveRunningHistoryUseCase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import javax.inject.Inject
66

77
class SaveRunningHistoryUseCase @Inject constructor(private val runningHistoryRepository: RunningHistoryRepository) {
88
suspend operator fun invoke(
9+
historyId: String,
910
startedAt: Long,
1011
finishedAt: Long,
1112
totalRunningTime: Int,
1213
pace: Double,
1314
totalDistance: Double
1415
): Result<RunningHistory> {
1516
return runningHistoryRepository.saveRunningHistory(
17+
historyId = historyId,
1618
startedAt = startedAt,
1719
finishedAt = finishedAt,
1820
totalRunningTime = totalRunningTime,

0 commit comments

Comments
 (0)