From cde7f6018a82296eb3fb8bc928516c0aeea7fda6 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 14:40:03 +0900 Subject: [PATCH 01/11] =?UTF-8?q?refactor=20:=20=EC=8B=B1=EA=B8=80?= =?UTF-8?q?=EA=B3=BC=20=EB=8C=80=EA=B2=B0=EB=AA=A8=EB=93=9C=EC=9D=98=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=EC=A1=B0=ED=9A=8C=20API=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EB=A5=BC=20=EB=8F=99=EC=9D=BC=ED=95=98=EA=B2=8C=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EA=B0=80=EA=B2=8C=20=EB=B0=94=EA=BF=88=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=EC=8D=A8=20RunningHistoryDetailResponse=EB=A1=9C=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...storyDetailResponse.kt => RunningHistoryDetailResponse.kt} | 4 ++-- .../core/network/model/response/SingleHistoryResponse.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/{SingleHistoryDetailResponse.kt => RunningHistoryDetailResponse.kt} (91%) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleHistoryDetailResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/RunningHistoryDetailResponse.kt similarity index 91% rename from core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleHistoryDetailResponse.kt rename to core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/RunningHistoryDetailResponse.kt index 9e72bcb7..123f2818 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleHistoryDetailResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/RunningHistoryDetailResponse.kt @@ -9,7 +9,7 @@ import online.partyrun.partyrunapplication.core.network.model.util.formatDate import online.partyrun.partyrunapplication.core.network.model.util.formatDistanceWithComma import java.time.LocalDateTime -data class SingleHistoryDetailResponse( +data class RunningHistoryDetailResponse( @SerializedName("id") val id: String?, @SerializedName("startTime") @@ -20,7 +20,7 @@ data class SingleHistoryDetailResponse( val distance: Double? ) -fun SingleHistoryDetailResponse.toDomainModel(): RunningHistoryDetail { +fun RunningHistoryDetailResponse.toDomainModel(): RunningHistoryDetail { val parsedDate = startTime?.let { LocalDateTime.parse( it, diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleHistoryResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleHistoryResponse.kt index 1bf81f3b..55fd0c1b 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleHistoryResponse.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/SingleHistoryResponse.kt @@ -5,7 +5,7 @@ import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHisto data class SingleHistoryResponse( @SerializedName("history") - val history: List? + val history: List? ) fun SingleHistoryResponse.toDomainModel(): SingleRunningHistory { From c2b92a4f54cb286a9e60b8a955d6d5e5a35ea9bf Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 14:41:39 +0900 Subject: [PATCH 02/11] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B2=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20data=20class=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/model/my_page/BattleRunningHistory.kt | 5 +++++ .../model/response/BattleHistoryResponse.kt | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/BattleRunningHistory.kt create mode 100644 core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleHistoryResponse.kt diff --git a/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/BattleRunningHistory.kt b/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/BattleRunningHistory.kt new file mode 100644 index 00000000..92bb41d7 --- /dev/null +++ b/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/BattleRunningHistory.kt @@ -0,0 +1,5 @@ +package online.partyrun.partyrunapplication.core.model.my_page + +data class BattleRunningHistory( + val history: List +) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleHistoryResponse.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleHistoryResponse.kt new file mode 100644 index 00000000..41dc950d --- /dev/null +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/model/response/BattleHistoryResponse.kt @@ -0,0 +1,14 @@ +package online.partyrun.partyrunapplication.core.network.model.response + +import com.google.gson.annotations.SerializedName +import online.partyrun.partyrunapplication.core.model.my_page.BattleRunningHistory + +data class BattleHistoryResponse( + @SerializedName("history") + val history: List? +) + +fun BattleHistoryResponse.toDomainModel(): BattleRunningHistory { + val transformedHistory = history?.map { it.toDomainModel() }?.reversed() ?: emptyList() + return BattleRunningHistory(history = transformedHistory) +} From 042d82254de137b4ce019979260e92132f59a313 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 14:41:58 +0900 Subject: [PATCH 03/11] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B2=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20ApiService=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/network/service/ResultApiService.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/service/ResultApiService.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/service/ResultApiService.kt index 79967eb4..11e291de 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/service/ResultApiService.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/service/ResultApiService.kt @@ -1,6 +1,7 @@ package online.partyrun.partyrunapplication.core.network.service import online.partyrun.partyrunapplication.core.common.network.ApiResponse +import online.partyrun.partyrunapplication.core.network.model.response.BattleHistoryResponse import online.partyrun.partyrunapplication.core.network.model.response.BattleResultResponse import online.partyrun.partyrunapplication.core.network.model.response.ComprehensiveRunRecordResponse import online.partyrun.partyrunapplication.core.network.model.response.SingleHistoryResponse @@ -26,4 +27,7 @@ interface ResultApiService { @GET("/api/mypage/singles") suspend fun getSingleHistory(): ApiResponse + @GET("/api/mypage/battles") + suspend fun getBattleHistory(): ApiResponse + } From df128575c8b8fe23c99493a074df3af82024cc64 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 14:42:44 +0900 Subject: [PATCH 04/11] =?UTF-8?q?feat=20:=20ResultDataSource=20=EB=8C=80?= =?UTF-8?q?=EA=B2=B0=20=EA=B8=B0=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/network/datasource/ResultDataSource.kt | 2 ++ .../core/network/datasource/ResultDataSourceImpl.kt | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSource.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSource.kt index 6eb92afb..9242f220 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSource.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSource.kt @@ -1,6 +1,7 @@ package online.partyrun.partyrunapplication.core.network.datasource import online.partyrun.partyrunapplication.core.common.network.ApiResponse +import online.partyrun.partyrunapplication.core.network.model.response.BattleHistoryResponse import online.partyrun.partyrunapplication.core.network.model.response.BattleResultResponse import online.partyrun.partyrunapplication.core.network.model.response.ComprehensiveRunRecordResponse import online.partyrun.partyrunapplication.core.network.model.response.SingleHistoryResponse @@ -11,4 +12,5 @@ interface ResultDataSource { suspend fun getSingleResults(singleId: String): ApiResponse suspend fun getComprehensiveRunRecord(): ApiResponse suspend fun getSingleHistory(): ApiResponse + suspend fun getBattleHistory(): ApiResponse } diff --git a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSourceImpl.kt b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSourceImpl.kt index 2d944f64..4246f3fa 100644 --- a/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSourceImpl.kt +++ b/core/network/src/main/java/online/partyrun/partyrunapplication/core/network/datasource/ResultDataSourceImpl.kt @@ -1,6 +1,7 @@ package online.partyrun.partyrunapplication.core.network.datasource import online.partyrun.partyrunapplication.core.common.network.ApiResponse +import online.partyrun.partyrunapplication.core.network.model.response.BattleHistoryResponse import online.partyrun.partyrunapplication.core.network.model.response.BattleResultResponse import online.partyrun.partyrunapplication.core.network.model.response.ComprehensiveRunRecordResponse import online.partyrun.partyrunapplication.core.network.model.response.SingleHistoryResponse @@ -23,4 +24,7 @@ class ResultDataSourceImpl @Inject constructor( override suspend fun getSingleHistory(): ApiResponse = resultApi.getSingleHistory() + override suspend fun getBattleHistory(): ApiResponse = + resultApi.getBattleHistory() + } From 9f1dc400291c74ddd10eb7f7a611fd06aaadf70a Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 14:44:03 +0900 Subject: [PATCH 05/11] =?UTF-8?q?feat=20:=20ResultRepository=20=EB=8C=80?= =?UTF-8?q?=EA=B2=B0=20=EA=B8=B0=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/repository/ResultRepository.kt | 3 +++ .../core/data/repository/ResultRepositoryImpl.kt | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepository.kt b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepository.kt index b1931d8a..60e9c41b 100644 --- a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepository.kt +++ b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepository.kt @@ -3,6 +3,7 @@ package online.partyrun.partyrunapplication.core.data.repository import kotlinx.coroutines.flow.Flow import online.partyrun.partyrunapplication.core.model.running_result.battle.BattleResult import online.partyrun.partyrunapplication.core.common.result.Result +import online.partyrun.partyrunapplication.core.model.my_page.BattleRunningHistory import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory import online.partyrun.partyrunapplication.core.model.running_result.single.SingleResult @@ -12,4 +13,6 @@ interface ResultRepository { suspend fun getSingleResults(): Flow> suspend fun getComprehensiveRunRecord(): Flow> suspend fun getSingleHistory(): Flow> + suspend fun getBattleHistory(): Flow> + } diff --git a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt index d02eecb8..bb01df89 100644 --- a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt +++ b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt @@ -10,6 +10,7 @@ import online.partyrun.partyrunapplication.core.network.model.response.toDomainM import online.partyrun.partyrunapplication.core.common.result.Result import online.partyrun.partyrunapplication.core.common.result.mapResultModel import online.partyrun.partyrunapplication.core.datastore.datasource.SinglePreferencesDataSource +import online.partyrun.partyrunapplication.core.model.my_page.BattleRunningHistory import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory import online.partyrun.partyrunapplication.core.model.running_result.single.SingleResult @@ -47,4 +48,10 @@ class ResultRepositoryImpl @Inject constructor( }.mapResultModel { it.toDomainModel() } } + override suspend fun getBattleHistory(): Flow> { + return apiRequestFlow { + resultDataSource.getBattleHistory() + }.mapResultModel { it.toDomainModel() } + } + } From c1ac499e16271de29d693e202de8deb2e5ad8213 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 19:16:40 +0900 Subject: [PATCH 06/11] =?UTF-8?q?feat=20:=20CombinedRunningHistory=20data?= =?UTF-8?q?=20class=20=EC=A0=95=EC=9D=98=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/model/my_page/CombinedRunningHistory.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/CombinedRunningHistory.kt diff --git a/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/CombinedRunningHistory.kt b/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/CombinedRunningHistory.kt new file mode 100644 index 00000000..5fa55a03 --- /dev/null +++ b/core/model/src/main/java/online/partyrun/partyrunapplication/core/model/my_page/CombinedRunningHistory.kt @@ -0,0 +1,6 @@ +package online.partyrun.partyrunapplication.core.model.my_page + +data class CombinedRunningHistory( + val singleRunningHistory: SingleRunningHistory = SingleRunningHistory(emptyList()), + val battleRunningHistory: BattleRunningHistory = BattleRunningHistory(emptyList()) +) From 1ada781eee9151b7b1ef227ea3208cb14e3f4d98 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 19:17:18 +0900 Subject: [PATCH 07/11] =?UTF-8?q?feat=20:=20MyPage=EC=97=90=EC=84=9C=20Bat?= =?UTF-8?q?tleResult=20Navigation=20=EC=B6=94=EA=B0=80=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../partyrunapplication/navigation/MainNavHost.kt | 7 +++++++ .../core/navigation/my_page/MyPageNavigation.kt | 2 ++ .../running_result/RunningResultNavigation.kt | 14 +++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/online/partyrun/partyrunapplication/navigation/MainNavHost.kt b/app/src/main/java/online/partyrun/partyrunapplication/navigation/MainNavHost.kt index 6ad989b0..7caaee20 100644 --- a/app/src/main/java/online/partyrun/partyrunapplication/navigation/MainNavHost.kt +++ b/app/src/main/java/online/partyrun/partyrunapplication/navigation/MainNavHost.kt @@ -116,6 +116,13 @@ fun SetUpMainNavGraph( } } }, + navigateToBattleResult = { isFromMyPage -> + navController.navigate("${MainNavRoutes.BattleResult.route}?isFromMyPage=$isFromMyPage") { + popUpTo(MainNavRoutes.MyPage.route) { + inclusive = false + } + } + }, onShowSnackbar = onShowSnackbar ) diff --git a/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/my_page/MyPageNavigation.kt b/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/my_page/MyPageNavigation.kt index 0f431f8f..b34d30b2 100644 --- a/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/my_page/MyPageNavigation.kt +++ b/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/my_page/MyPageNavigation.kt @@ -11,6 +11,7 @@ fun NavGraphBuilder.myPageRoute( navigateToMyPage: () -> Unit, navigateToProfile: () -> Unit, navigateToSingleResult: (Boolean) -> Unit, + navigateToBattleResult: (Boolean) -> Unit, onShowSnackbar: (String) -> Unit ) { composable(route = MainNavRoutes.MyPage.route) { @@ -18,6 +19,7 @@ fun NavGraphBuilder.myPageRoute( navigateToSettings = navigateToSettings, navigateToProfile = navigateToProfile, navigateToSingleResult = navigateToSingleResult, + navigateToBattleResult = navigateToBattleResult, onShowSnackbar = onShowSnackbar ) } diff --git a/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/running_result/RunningResultNavigation.kt b/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/running_result/RunningResultNavigation.kt index 2d69a8a7..fc68925f 100644 --- a/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/running_result/RunningResultNavigation.kt +++ b/core/navigation/src/main/java/online/partyrun/partyrunapplication/core/navigation/running_result/RunningResultNavigation.kt @@ -12,11 +12,23 @@ fun NavGraphBuilder.runningResultRoute( navigateToTopLevel: () -> Unit, navigateToBack: () -> Unit ) { - composable(route = MainNavRoutes.BattleResult.route) { + composable( + route = "${MainNavRoutes.BattleResult.route}?isFromMyPage={isFromMyPage}", + arguments = listOf( + navArgument("isFromMyPage") { + type = NavType.BoolType + defaultValue = false + } + ) + ) { backStackEntry -> + val isFromMyPage = backStackEntry.arguments?.getBoolean("isFromMyPage") ?: false BattleResultScreen( + isFromMyPage = isFromMyPage, navigateToTopLevel = navigateToTopLevel, + navigateToBack = navigateToBack ) } + composable( route = "${MainNavRoutes.SingleResult.route}?isFromMyPage={isFromMyPage}", arguments = listOf( From 2991166f92e428636dcd34fdd702741fcf1a6f91 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 19:20:15 +0900 Subject: [PATCH 08/11] =?UTF-8?q?feat=20:=20=EC=8B=B1=EA=B8=80,=20?= =?UTF-8?q?=EB=8C=80=EA=B2=B0=20=EA=B8=B0=EB=A1=9D=EC=9D=84=20Combine?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=ED=95=9C=20=EB=B2=88=EC=97=90=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=20=EC=B2=98=EB=A6=AC=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../my_page/GetRunningHistoryUseCase.kt | 27 +++++++++++++++++++ .../domain/my_page/GetSingleHistoryUseCase.kt | 11 -------- .../feature/my_page/MyPageUiState.kt | 4 +-- .../feature/my_page/MyPageViewModel.kt | 26 ++++++++++-------- 4 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetRunningHistoryUseCase.kt delete mode 100644 core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetSingleHistoryUseCase.kt diff --git a/core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetRunningHistoryUseCase.kt b/core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetRunningHistoryUseCase.kt new file mode 100644 index 00000000..0a69d240 --- /dev/null +++ b/core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetRunningHistoryUseCase.kt @@ -0,0 +1,27 @@ +package online.partyrun.partyrunapplication.core.domain.my_page + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.combine +import online.partyrun.partyrunapplication.core.data.repository.ResultRepository +import online.partyrun.partyrunapplication.core.model.my_page.CombinedRunningHistory +import online.partyrun.partyrunapplication.core.common.result.Result +import javax.inject.Inject + +class GetRunningHistoryUseCase @Inject constructor( + private val resultRepository: ResultRepository +) { + suspend operator fun invoke(): Flow> { + return combine( + resultRepository.getSingleHistory(), + resultRepository.getBattleHistory() + ) { single, battle -> + when { + single is Result.Loading || battle is Result.Loading -> Result.Loading + single is Result.Success && battle is Result.Success -> + Result.Success(CombinedRunningHistory(single.data, battle.data)) + + else -> Result.Failure("Failed to fetch combined running history", code = -1) + } + } + } +} diff --git a/core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetSingleHistoryUseCase.kt b/core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetSingleHistoryUseCase.kt deleted file mode 100644 index 27f33be1..00000000 --- a/core/domain/src/main/java/online/partyrun/partyrunapplication/core/domain/my_page/GetSingleHistoryUseCase.kt +++ /dev/null @@ -1,11 +0,0 @@ -package online.partyrun.partyrunapplication.core.domain.my_page - -import online.partyrun.partyrunapplication.core.data.repository.ResultRepository -import javax.inject.Inject - -class GetSingleHistoryUseCase @Inject constructor( - private val resultRepository: ResultRepository -) { - suspend operator fun invoke() = resultRepository.getSingleHistory() - -} diff --git a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageUiState.kt b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageUiState.kt index 43ec2b2c..1d4c175b 100644 --- a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageUiState.kt +++ b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageUiState.kt @@ -1,7 +1,7 @@ package online.partyrun.partyrunapplication.feature.my_page +import online.partyrun.partyrunapplication.core.model.my_page.CombinedRunningHistory import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord -import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory import online.partyrun.partyrunapplication.core.model.user.User enum class ModeType { @@ -40,7 +40,7 @@ sealed class RunningHistoryState { object Loading : RunningHistoryState() data class Success( - val singleRunningHistory: SingleRunningHistory = SingleRunningHistory(emptyList()) + val combinedRunningHistory: CombinedRunningHistory = CombinedRunningHistory() ) : RunningHistoryState() object LoadFailed : RunningHistoryState() diff --git a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt index 7f12737b..f390d0f5 100644 --- a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt +++ b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt @@ -12,7 +12,8 @@ import online.partyrun.partyrunapplication.core.common.result.onFailure import online.partyrun.partyrunapplication.core.common.result.onSuccess import online.partyrun.partyrunapplication.core.domain.my_page.GetComprehensiveRunRecordUseCase import online.partyrun.partyrunapplication.core.domain.my_page.GetMyPageDataUseCase -import online.partyrun.partyrunapplication.core.domain.my_page.GetSingleHistoryUseCase +import online.partyrun.partyrunapplication.core.domain.my_page.GetRunningHistoryUseCase +import online.partyrun.partyrunapplication.core.domain.running.battle.SaveBattleIdUseCase import online.partyrun.partyrunapplication.core.domain.running.single.SaveSingleIdUseCase import timber.log.Timber import javax.inject.Inject @@ -21,8 +22,9 @@ import javax.inject.Inject class MyPageViewModel @Inject constructor( private val getMyPageDataUseCase: GetMyPageDataUseCase, private val getComprehensiveRunRecordUseCase: GetComprehensiveRunRecordUseCase, - private val getSingleHistoryUseCase: GetSingleHistoryUseCase, - private val saveSingleIdUseCase: SaveSingleIdUseCase + private val getRunningHistoryUseCase: GetRunningHistoryUseCase, + private val saveSingleIdUseCase: SaveSingleIdUseCase, + private val saveBattleIdUseCase: SaveBattleIdUseCase ) : ViewModel() { private val _myPageProfileState = MutableStateFlow(MyPageProfileState.Loading) @@ -68,25 +70,22 @@ class MyPageViewModel @Inject constructor( ) }.onFailure { errorMessage, code -> Timber.e(errorMessage, code) - _snackbarMessage.value = "종합기록을 불러오는데 실패했습니다." + _snackbarMessage.value = "종합기록을 불러오는데\n실패했습니다." _myPageComprehensiveRunRecordState.value = MyPageComprehensiveRunRecordState.LoadFailed } } } - - fun getSingleRunningHistory() = viewModelScope.launch { - _runningHistoryState.value = RunningHistoryState.Loading - - getSingleHistoryUseCase().collect { result -> + fun getRunningHistory() = viewModelScope.launch { + getRunningHistoryUseCase().collect { result -> result.onSuccess { _runningHistoryState.value = RunningHistoryState.Success( - singleRunningHistory = it + combinedRunningHistory = it ) }.onFailure { errorMessage, code -> Timber.e(errorMessage, code) - _snackbarMessage.value = "싱글 기록을 불러오는데\n실패했습니다." + _snackbarMessage.value = "이전 기록을 불러오는데\n실패했습니다." _runningHistoryState.value = RunningHistoryState.LoadFailed } @@ -98,6 +97,11 @@ class MyPageViewModel @Inject constructor( saveIdCompleteEvent.emit(ModeType.SINGLE) } + fun saveBattleId(battleId: String) = viewModelScope.launch { + saveBattleIdUseCase(battleId) + saveIdCompleteEvent.emit(ModeType.BATTLE) + } + fun clearSnackbarMessage() { _snackbarMessage.value = "" } From dc9a48a7f03d29e66a869c34f34e908842084c95 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 19:20:45 +0900 Subject: [PATCH 09/11] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B2=B0=EB=AA=A8?= =?UTF-8?q?=EB=93=9C=20=EB=9F=AC=EB=8B=9D=20=EA=B8=B0=EB=A1=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B2=B0=EA=B3=BC=20Screen=20=EB=B0=98=EC=98=81=20?= =?UTF-8?q?#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/my_page/MyPageScreen.kt | 91 ++++++++++++++----- 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt index 02a341b4..2e769044 100644 --- a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt +++ b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt @@ -41,6 +41,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import online.partyrun.partyrunapplication.core.designsystem.component.PartyRunGradientRoundedRect import online.partyrun.partyrunapplication.core.designsystem.component.PartyRunTopAppBar import online.partyrun.partyrunapplication.core.designsystem.icon.PartyRunIcons +import online.partyrun.partyrunapplication.core.model.my_page.BattleRunningHistory import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory import online.partyrun.partyrunapplication.core.model.user.User import online.partyrun.partyrunapplication.core.ui.ProfileSection @@ -57,6 +58,7 @@ fun MyPageScreen( navigateToSettings: () -> Unit = {}, navigateToProfile: () -> Unit = {}, navigateToSingleResult: (Boolean) -> Unit = {}, + navigateToBattleResult: (Boolean) -> Unit = {}, onShowSnackbar: (String) -> Unit ) { val myPageProfileState by myPageViewModel.myPageProfileState.collectAsStateWithLifecycle() @@ -68,6 +70,7 @@ fun MyPageScreen( navigateToSettings = navigateToSettings, navigateToProfile = navigateToProfile, navigateToSingleResult = navigateToSingleResult, + navigateToBattleResult = navigateToBattleResult, onShowSnackbar = onShowSnackbar, myPageSnackbarMessage = myPageSnackbarMessage ) @@ -82,6 +85,7 @@ fun Content( navigateToSettings: () -> Unit, navigateToProfile: () -> Unit, navigateToSingleResult: (Boolean) -> Unit, + navigateToBattleResult: (Boolean) -> Unit, onShowSnackbar: (String) -> Unit, myPageSnackbarMessage: String ) { @@ -112,7 +116,8 @@ fun Content( userData = myPageProfileState.user, myPageViewModel = myPageViewModel, navigateToProfile = navigateToProfile, - navigateToSingleResult = navigateToSingleResult + navigateToSingleResult = navigateToSingleResult, + navigateToBattleResult = navigateToBattleResult ) is MyPageProfileState.LoadFailed -> LoadingBody() @@ -161,20 +166,19 @@ private fun MyPageBody( userData: User, myPageViewModel: MyPageViewModel, navigateToProfile: () -> Unit, - navigateToSingleResult: (Boolean) -> Unit + navigateToSingleResult: (Boolean) -> Unit, + navigateToBattleResult: (Boolean) -> Unit ) { LaunchedEffect(Unit) { myPageViewModel.getComprehensiveRunRecord() - myPageViewModel.getSingleRunningHistory() + myPageViewModel.getRunningHistory() } LaunchedEffect(Unit) {// 러닝 기록 상세 보기 클릭 myPageViewModel.saveIdCompleteEvent.collect { modeType -> when (modeType) { ModeType.SINGLE -> navigateToSingleResult(true) // MyPage로부터 Result로의 이동은 true - else -> { - // Battle - } + ModeType.BATTLE -> navigateToBattleResult(true) } } } @@ -214,21 +218,10 @@ private fun MyPageBody( ) Spacer(modifier = Modifier.height(30.dp)) - Column( - modifier = Modifier - .fillMaxWidth() - .padding(start = 20.dp) - ) { - Text( - text = stringResource(id = R.string.battle_title), - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onPrimary, - ) - Spacer(modifier = Modifier.height(30.dp)) - - EmptyRunningHistory() - - } + BattleRunningHistoryRow( + runningHistoryState = runningHistoryState, + myPageViewModel = myPageViewModel + ) Spacer(modifier = Modifier.height(80.dp)) } @@ -242,11 +235,27 @@ private fun SingleRunningHistoryRow( when (runningHistoryState) { is RunningHistoryState.Loading -> ShimmerRunningHistory(isSingleData = true) is RunningHistoryState.Success -> SingleRunningHistoryBody( - singleRunningHistory = runningHistoryState.singleRunningHistory, + singleRunningHistory = runningHistoryState.combinedRunningHistory.singleRunningHistory, myPageViewModel = myPageViewModel ) - RunningHistoryState.LoadFailed -> ShimmerRunningHistory(isSingleData = true) + RunningHistoryState.LoadFailed -> EmptyRunningHistory() + } +} + +@Composable +private fun BattleRunningHistoryRow( + runningHistoryState: RunningHistoryState, + myPageViewModel: MyPageViewModel +) { + when (runningHistoryState) { + is RunningHistoryState.Loading -> ShimmerRunningHistory(isSingleData = false) + is RunningHistoryState.Success -> BattleRunningHistoryBody( + battleRunningHistory = runningHistoryState.combinedRunningHistory.battleRunningHistory, + myPageViewModel = myPageViewModel + ) + + RunningHistoryState.LoadFailed -> EmptyRunningHistory() } } @@ -286,6 +295,42 @@ private fun SingleRunningHistoryBody( } } +@Composable +private fun BattleRunningHistoryBody( + battleRunningHistory: BattleRunningHistory, + myPageViewModel: MyPageViewModel +) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(start = 20.dp) + ) { + Text( + text = stringResource(id = R.string.battle_title), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onPrimary, + ) + Spacer(modifier = Modifier.height(30.dp)) + + if (battleRunningHistory.history.isEmpty()) { + EmptyRunningHistory() + } else { + LazyRow( + horizontalArrangement = Arrangement.spacedBy(20.dp) + ) { + items(battleRunningHistory.history) { data -> + RunningDataCard( + runningHistoryDetail = data, + isSingleData = false + ) { + myPageViewModel.saveBattleId(data.id) + } + } + } + } + } +} + @Composable private fun ComprehensiveRunRecordRect( myPageComprehensiveRunRecordState: MyPageComprehensiveRunRecordState From f57e2f308cb0526e8640a55856390222dda1a8da Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 19:21:53 +0900 Subject: [PATCH 10/11] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B2=B0=EB=AA=A8?= =?UTF-8?q?=EB=93=9C=20=EA=B2=B0=EA=B3=BC=20=EC=8A=A4=ED=81=AC=EB=A6=B0?= =?UTF-8?q?=EC=97=90=EB=8F=84=20navigateToBack()=20=EC=A0=84=EB=8B=AC=20#P?= =?UTF-8?q?AR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/BattleResultScreen.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/feature/running_result/src/main/java/online/partyrun/partyrunapplication/feature/running_result/battle/BattleResultScreen.kt b/feature/running_result/src/main/java/online/partyrun/partyrunapplication/feature/running_result/battle/BattleResultScreen.kt index 50d9ac01..1cdbde1f 100644 --- a/feature/running_result/src/main/java/online/partyrun/partyrunapplication/feature/running_result/battle/BattleResultScreen.kt +++ b/feature/running_result/src/main/java/online/partyrun/partyrunapplication/feature/running_result/battle/BattleResultScreen.kt @@ -53,33 +53,41 @@ import online.partyrun.partyrunapplication.feature.running_result.ui.SummaryInfo @Composable fun BattleResultScreen( modifier: Modifier = Modifier, + isFromMyPage: Boolean = false, battleResultViewModel: BattleResultViewModel = hiltViewModel(), - navigateToTopLevel: () -> Unit + navigateToTopLevel: () -> Unit, + navigateToBack: () -> Unit ) { val battleResultUiState by battleResultViewModel.battleResultUiState.collectAsStateWithLifecycle() Content( modifier = modifier, + isFromMyPage = isFromMyPage, battleResultUiState = battleResultUiState, battleResultViewModel = battleResultViewModel, - navigateToTopLevel = navigateToTopLevel + navigateToTopLevel = navigateToTopLevel, + navigateToBack = navigateToBack ) } @Composable private fun Content( modifier: Modifier = Modifier, + isFromMyPage: Boolean, battleResultUiState: BattleResultUiState, battleResultViewModel: BattleResultViewModel, navigateToTopLevel: () -> Unit, + navigateToBack: () -> Unit ) { Box(modifier = modifier) { when (battleResultUiState) { is BattleResultUiState.Loading -> ResultLoadingBody() is BattleResultUiState.Success -> BattleResultBody( + isFromMyPage = isFromMyPage, battleResult = battleResultUiState.battleResult, - navigateToTopLevel = navigateToTopLevel + navigateToTopLevel = navigateToTopLevel, + navigateToBack = navigateToBack ) is BattleResultUiState.LoadFailed -> @@ -93,7 +101,9 @@ private fun Content( @Composable private fun BattleResultBody( battleResult: BattleResultUiModel, - navigateToTopLevel: () -> Unit + isFromMyPage: Boolean, + navigateToTopLevel: () -> Unit, + navigateToBack: () -> Unit ) { // userID에 해당하는 러너 찾기 val userStatus = battleResult.battleRunnerStatus.find { it.id == battleResult.userId } @@ -201,7 +211,9 @@ private fun BattleResultBody( shadowElevation = 5.dp ) { FixedBottomNavigationSheet( - navigateToTopLevel = navigateToTopLevel + isFromMyPage = isFromMyPage, + navigateToTopLevel = navigateToTopLevel, + navigateToBack = navigateToBack ) } } From ed805fad6eb6c0b1dcc1b99b3410b057a00c794b Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 19:25:08 +0900 Subject: [PATCH 11/11] =?UTF-8?q?feat=20:=20MyPageViewModel=20getRunningHi?= =?UTF-8?q?story()=20Loading=20State=20=EC=B2=98=EB=A6=AC=20#PAR-382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit API 호출 시 Loading State로 바꿔 ShimmerEffect 적용 --- .../partyrunapplication/feature/my_page/MyPageViewModel.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt index f390d0f5..aae45bf4 100644 --- a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt +++ b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt @@ -78,6 +78,8 @@ class MyPageViewModel @Inject constructor( } fun getRunningHistory() = viewModelScope.launch { + _runningHistoryState.value = RunningHistoryState.Loading + getRunningHistoryUseCase().collect { result -> result.onSuccess { _runningHistoryState.value = RunningHistoryState.Success(