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/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() } + } + } 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/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/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()) +) 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( 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() + } 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) +} 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 { 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 + } 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 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..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 @@ -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,24 @@ class MyPageViewModel @Inject constructor( ) }.onFailure { errorMessage, code -> Timber.e(errorMessage, code) - _snackbarMessage.value = "종합기록을 불러오는데 실패했습니다." + _snackbarMessage.value = "종합기록을 불러오는데\n실패했습니다." _myPageComprehensiveRunRecordState.value = MyPageComprehensiveRunRecordState.LoadFailed } } } - - fun getSingleRunningHistory() = viewModelScope.launch { + fun getRunningHistory() = viewModelScope.launch { _runningHistoryState.value = RunningHistoryState.Loading - getSingleHistoryUseCase().collect { result -> + 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 +99,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 = "" } 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 ) } }