Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”€ :: (#214) - Expo_Id의 νƒ€μž…μ„ Longμ—μ„œ String으둜 λ°˜ν™˜ν•©λ‹ˆλ‹€. #215

Merged
merged 11 commits into from
Nov 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import kotlinx.coroutines.flow.Flow

interface ExpoRepository {
fun getExpoList() : Flow<List<ExpoListResponseEntity>>
fun getExpoInformation(expoId: Long) : Flow<ExpoRequestAndResponseModel>
fun getExpoInformation(expoId: String) : Flow<ExpoRequestAndResponseModel>
fun registerExpoInformation(body: ExpoRequestAndResponseModel) : Flow<Unit>
fun modifyExpoInformation(expoId: Long, body: ExpoRequestAndResponseModel) : Flow<Unit>
fun deleteExpoInformation(expoId: Long) : Flow<Unit>
fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponseModel) : Flow<Unit>
fun deleteExpoInformation(expoId: String) : Flow<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExpoRepositoryImpl @Inject constructor(
}
}

override fun getExpoInformation(expoId: Long): Flow<ExpoRequestAndResponseModel> {
override fun getExpoInformation(expoId: String): Flow<ExpoRequestAndResponseModel> {
return dataSource.getExpoInformation(expoId = expoId).transform { response ->
emit(response.toModel())
}
Expand All @@ -30,7 +30,7 @@ class ExpoRepositoryImpl @Inject constructor(
}

override fun modifyExpoInformation(
expoId: Long,
expoId: String,
body: ExpoRequestAndResponseModel
): Flow<Unit> {
return dataSource.modifyExpoInformation(
Expand All @@ -39,7 +39,7 @@ class ExpoRepositoryImpl @Inject constructor(
)
}

override fun deleteExpoInformation(expoId: Long): Flow<Unit> {
override fun deleteExpoInformation(expoId: String): Flow<Unit> {
return dataSource.deleteExpoInformation(expoId = expoId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.inject.Inject
class DeleteExpoInformationUseCase @Inject constructor(
private val repository: ExpoRepository
) {
operator fun invoke(expoId: Long) = runCatching {
operator fun invoke(expoId: String) = runCatching {
repository.deleteExpoInformation(expoId = expoId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import javax.inject.Inject
class GetExpoInformationUseCase @Inject constructor(
private val repository: ExpoRepository
) {
operator fun invoke(expoId: Long) : Flow<ExpoRequestAndResponseModel> =
operator fun invoke(expoId: String) : Flow<ExpoRequestAndResponseModel> =
repository.getExpoInformation(expoId = expoId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ModifyExpoInformationUseCase @Inject constructor(
private val repository: ExpoRepository
) {
operator fun invoke(
expoId: Long,
expoId: String,
body: ExpoRequestAndResponseModel
) = runCatching {
repository.modifyExpoInformation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.school_of_company.model.entity.expo

data class ExpoListResponseEntity(
val id: Long,
val id: String,
val title: String,
val description: String,
val startedDay: String, // yyyy-mm-dd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ExpoAPI {

@GET("/expo/{expo_id}")
suspend fun getExpoInformation(
@Path("expo_id") expoId: Long
@Path("expo_id") expoId: String
) : ExpoRequestAndResponse

@POST("/expo")
Expand All @@ -21,12 +21,12 @@ interface ExpoAPI {

@PATCH("/expo/{expo_id}")
suspend fun modifyExpoInformation(
@Path("expo_id") expoId: Long,
@Path("expo_id") expoId: String,
@Body body: ExpoRequestAndResponse
)

@DELETE("/expo/{expo_id}")
suspend fun deleteExpoInformation(
@Path("expo_id") expoId: Long
@Path("expo_id") expoId: String
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import kotlinx.coroutines.flow.Flow

interface ExpoDataSource {
fun getExpoList() : Flow<List<ExpoListResponse>>
fun getExpoInformation(expoId: Long) : Flow<ExpoRequestAndResponse>
fun getExpoInformation(expoId: String) : Flow<ExpoRequestAndResponse>
fun registerExpoInformation(body: ExpoRequestAndResponse) : Flow<Unit>
fun modifyExpoInformation(expoId: Long, body: ExpoRequestAndResponse) : Flow<Unit>
fun deleteExpoInformation(expoId: Long) : Flow<Unit>
fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse) : Flow<Unit>
fun deleteExpoInformation(expoId: String) : Flow<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ class ExpoDataSourceImpl @Inject constructor(
override fun getExpoList(): Flow<List<ExpoListResponse>> =
performApiRequest { service.getExpoList() }

override fun getExpoInformation(expoId: Long): Flow<ExpoRequestAndResponse> =
override fun getExpoInformation(expoId: String): Flow<ExpoRequestAndResponse> =
performApiRequest { service.getExpoInformation(expoId = expoId) }

override fun registerExpoInformation(body: ExpoRequestAndResponse): Flow<Unit> =
performApiRequest { service.registerExpoInformation(body = body) }

override fun modifyExpoInformation(expoId: Long, body: ExpoRequestAndResponse): Flow<Unit> =
override fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse): Flow<Unit> =
performApiRequest { service.modifyExpoInformation(
expoId = expoId,
body = body
) }

override fun deleteExpoInformation(expoId: Long): Flow<Unit> =
override fun deleteExpoInformation(expoId: String): Flow<Unit> =
performApiRequest { service.deleteExpoInformation(expoId = expoId) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class ExpoListResponse(
@Json(name = "id") val id: Long,
@Json(name = "id") val id: String,
@Json(name = "title") val title: String,
@Json(name = "description") val description: String,
@Json(name = "startedDay") val startedDay: String, // yyyy-mm-dd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun NavController.navigateToHome(navOptions: NavOptions? = null) {
}

fun NavController.navigateToExpoDetail(
id: Long,
id: String,
navOptions: NavOptions? = null
) {
this.navigate(
Expand All @@ -29,7 +29,7 @@ fun NavController.navigateToExpoDetail(
}

fun NavController.navigateToExpoModify(
id: Long,
id: String,
navOptions: NavOptions? = null
) {
this.navigate(
Expand All @@ -43,7 +43,7 @@ fun NavController.navigateToExpoCreate(navOptions: NavOptions? = null) {
}

fun NavGraphBuilder.expoScreen(
navigationToDetail: (Long) -> Unit
navigationToDetail: (String) -> Unit
) {
composable(route = homeRoute) {
ExpoRoute(
Expand All @@ -57,22 +57,20 @@ fun NavGraphBuilder.expoDetailScreen(
onMessageClick: () -> Unit,
onCheckClick: () -> Unit,
onQrGenerateClick: () -> Unit,
onModifyClick: (Long) -> Unit,
onModifyClick: (String) -> Unit,
onProgramClick: () -> Unit
) {
composable(route = "$expoDetailRoute/{id}") { backStackEntry ->
val id = backStackEntry.arguments?.getString("id")?.toLongOrNull()
if (id != null) {
ExpoDetailRoute(
id = id,
onBackClick = onBackClick,
onMessageClick = onMessageClick,
onCheckClick = onCheckClick,
onQrGenerateClick = onQrGenerateClick,
onModifyClick = onModifyClick,
onProgramClick = onProgramClick
)
}
val id = backStackEntry.arguments?.getString("id") ?: ""
ExpoDetailRoute(
id = id,
onBackClick = onBackClick,
onMessageClick = onMessageClick,
onCheckClick = onCheckClick,
onQrGenerateClick = onQrGenerateClick,
onModifyClick = onModifyClick,
onProgramClick = onProgramClick
)
audgns10 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -81,14 +79,12 @@ fun NavGraphBuilder.expoModifyScreen(
onErrorToast: (throwable: Throwable?, message: Int?) -> Unit
) {
composable(route = "$expoModifyRoute/{id}") { backStackEntry ->
val id = backStackEntry.arguments?.getString("id")?.toLongOrNull()
if (id != null) {
ExpoModifyRoute(
id = id,
onBackClick = onBackClick,
onErrorToast = onErrorToast
)
}
val id = backStackEntry.arguments?.getString("id") ?: ""
ExpoModifyRoute(
id = id,
onBackClick = onBackClick,
onErrorToast = onErrorToast
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ import com.school_of_company.ui.util.formatServerDate

@Composable
internal fun ExpoDetailRoute(
id: Long,
id: String,
onBackClick: () -> Unit,
onMessageClick: () -> Unit,
onCheckClick: () -> Unit,
onQrGenerateClick: () -> Unit,
onModifyClick: (Long) -> Unit,
onModifyClick: (String) -> Unit,
onProgramClick: () -> Unit,
viewModel: ExpoViewModel = hiltViewModel()
) {
Expand All @@ -82,7 +82,7 @@ internal fun ExpoDetailRoute(

@Composable
internal fun ExpoDetailScreen(
id: Long,
id: String,
modifier: Modifier = Modifier,
scrollState: ScrollState = rememberScrollState(),
getExpoInformationUiState: GetExpoInformationUiState,
Expand All @@ -91,7 +91,7 @@ internal fun ExpoDetailScreen(
onMessageClick: () -> Unit,
onCheckClick: () -> Unit,
onQrGenerateClick: () -> Unit,
onModifyClick: (Long) -> Unit,
onModifyClick: (String) -> Unit,
onProgramClick: () -> Unit
) {
val (openDialog, isOpenDialog) = rememberSaveable { mutableStateOf(false) }
Expand Down Expand Up @@ -421,6 +421,6 @@ private fun HomeDetailScreenPreview() {
onProgramClick = {},
qrData = QrCode(content = "121231342352"),
getExpoInformationUiState = GetExpoInformationUiState.Loading,
id = 0
id = ""
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import com.school_of_company.ui.toast.makeToast
@Composable
internal fun ExpoModifyRoute(
onBackClick: () -> Unit,
id: Long,
id: String,
onErrorToast: (throwable: Throwable?, message: Int?) -> Unit,
viewModel: ExpoViewModel = hiltViewModel()
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import kotlinx.collections.immutable.toImmutableList

@Composable
internal fun ExpoRoute(
navigationToDetail: (Long) -> Unit,
navigationToDetail: (String) -> Unit,
viewModel: ExpoViewModel = hiltViewModel()
) {
val swipeRefreshLoading by viewModel.swipeRefreshLoading.collectAsStateWithLifecycle()
Expand All @@ -74,7 +74,7 @@ internal fun ExpoScreen(
swipeRefreshState: SwipeRefreshState,
getExpoListData: GetExpoListUiState,
getExpoList: () -> Unit,
navigationToDetail: (Long) -> Unit
navigationToDetail: (String) -> Unit
) {
var filterButtonText by rememberSaveable { mutableStateOf("μ΅œμ‹ μˆœ") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun ExpoList(
modifier: Modifier = Modifier,
emptyList: Boolean = false,
item: ImmutableList<ExpoListResponseEntity> = persistentListOf(),
navigateToExpoDetail: (Long) -> Unit,
navigateToExpoDetail: (String) -> Unit,
scrollState: ScrollState = rememberScrollState()
) {
ExpoAndroidTheme { colors, typography ->
Expand Down Expand Up @@ -75,7 +75,7 @@ private fun HomeListPreview() {
ExpoList(
item = persistentListOf(
ExpoListResponseEntity(
id = 0,
id = "",
coverImage = "https://image.dongascience.com/Photo/2019/12/fb4f7da04758d289a466f81478f5f488.jpg",
startedDay = "09-01",
finishedDay = "09-30",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.school_of_company.ui.util.formatServerDate
fun ExpoListItem(
modifier: Modifier = Modifier,
data: ExpoListResponseEntity,
navigateToExpoDetail: (Long) -> Unit
navigateToExpoDetail: (String) -> Unit
) {
ExpoAndroidTheme { colors, typography ->

Expand Down Expand Up @@ -197,7 +197,7 @@ fun ExpoListItem(
private fun HomeListItemPreview() {
ExpoListItem(
data = ExpoListResponseEntity(
id = 0,
id = "",
coverImage = "https://image.dongascience.com/Photo/2019/12/fb4f7da04758d289a466f81478f5f488.jpg",
startedDay = "09-01",
finishedDay = "09-30",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ExpoViewModel @Inject constructor(

internal var cover_image = savedStateHandle.getStateFlow(key = COVER_IMAGE, initialValue = "")

internal fun getExpoInformation(expoId: Long) = viewModelScope.launch {
internal fun getExpoInformation(expoId: String) = viewModelScope.launch {
getExpoInformationUseCase(expoId = expoId)
.asResult()
.collectLatest { result ->
Expand Down Expand Up @@ -132,7 +132,7 @@ class ExpoViewModel @Inject constructor(
}

internal fun modifyExpoInformation(
expoId: Long,
expoId: String,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

expoId νƒ€μž… 변경이 μ™„λ£Œλ˜μ—ˆμœΌλ‚˜, μ—λŸ¬ 처리 νŒ¨ν„΄μ˜ 일관성이 ν•„μš”ν•©λ‹ˆλ‹€.

registerExpoInformationμ—μ„œ μ‚¬μš©λœ asResult() νŒ¨ν„΄κ³Ό λ™μΌν•œ λ°©μ‹μœΌλ‘œ κ΅¬ν˜„ν•˜λŠ” 것이 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같은 변경을 μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

 internal fun modifyExpoInformation(
     expoId: String,
     body: ExpoRequestAndResponseModel
 ) = viewModelScope.launch {
     _modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Loading
     modifyExpoInformationUseCase(
         expoId = expoId,
         body = body
     )
-        .onSuccess {
-            it.catch { remoteError ->
-                _modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Error(remoteError)
-            }.collect {
-                _modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Success
-            }
-        }
-        .onFailure { error ->
-            _modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Error(error)
-        }
+        .asResult()
+        .collectLatest { result ->
+            when (result) {
+                is Result.Loading -> _modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Loading
+                is Result.Success -> _modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Success
+                is Result.Error -> {
+                    Log.e("ExpoViewModel", "μˆ˜μ • μ‹€νŒ¨", result.exception)
+                    _modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Error(result.exception)
+                }
+            }
+        }

Committable suggestion skipped: line range outside the PR's diff.

body: ExpoRequestAndResponseModel
) = viewModelScope.launch {
_modifyExpoInformationUiState.value = ModifyExpoInformationUiState.Loading
Expand Down Expand Up @@ -168,7 +168,7 @@ class ExpoViewModel @Inject constructor(
}
}

internal fun deleteExpoInformation(expoId: Long) = viewModelScope.launch {
internal fun deleteExpoInformation(expoId: String) = viewModelScope.launch {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

expoId νƒ€μž… 변경이 μ™„λ£Œλ˜μ—ˆμœΌλ‚˜, μ—λŸ¬ 처리 νŒ¨ν„΄μ˜ 톡일이 ν•„μš”ν•©λ‹ˆλ‹€.

λ‹€λ₯Έ ν•¨μˆ˜λ“€κ³Ό λ™μΌν•œ μ—λŸ¬ 처리 νŒ¨ν„΄μ„ μ‚¬μš©ν•˜μ—¬ μ½”λ“œμ˜ 일관성을 μœ μ§€ν•˜λŠ” 것이 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같은 변경을 μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

 internal fun deleteExpoInformation(expoId: String) = viewModelScope.launch {
     _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Loading
     deleteExpoInformationUseCase(expoId = expoId)
-        .onSuccess {
-            it.catch { remoteError ->
-                _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Error(remoteError)
-            }.collect {
-                _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Success
-            }
-        }
-        .onFailure { error ->
-            _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Error(error)
-        }
+        .asResult()
+        .collectLatest { result ->
+            when (result) {
+                is Result.Loading -> _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Loading
+                is Result.Success -> _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Success
+                is Result.Error -> {
+                    Log.e("ExpoViewModel", "μ‚­μ œ μ‹€νŒ¨", result.exception)
+                    _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Error(result.exception)
+                }
+            }
+        }

Committable suggestion skipped: line range outside the PR's diff.

_deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Loading
deleteExpoInformationUseCase(expoId = expoId)
.onSuccess {
Expand Down
Loading