From 5bffb4923900f9c9859bc4b8b630b09391fe7b44 Mon Sep 17 00:00:00 2001 From: Gimun Kim <101035437+kmkim2689@users.noreply.github.com> Date: Fri, 25 Oct 2024 09:54:24 +0900 Subject: [PATCH] :bug: fix edit --- .../repository/edit/EditRecipeRepository.kt | 2 +- .../model/recipemaking/RecipeCreation.kt | 1 + .../presentation/edit/EditRecipeViewModel.kt | 26 +++++++++++-------- .../edit/step/EditStepsViewModel.kt | 9 ++++++- .../making/step/StepMakingViewModel.kt | 1 + 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/java/net/pengcook/android/data/repository/edit/EditRecipeRepository.kt b/android/app/src/main/java/net/pengcook/android/data/repository/edit/EditRecipeRepository.kt index 0325cc43..a6739eac 100644 --- a/android/app/src/main/java/net/pengcook/android/data/repository/edit/EditRecipeRepository.kt +++ b/android/app/src/main/java/net/pengcook/android/data/repository/edit/EditRecipeRepository.kt @@ -84,7 +84,7 @@ object EditRecipeRepository { private fun RecipeCreation.toSavedRecipeDescription(): SavedRecipeDescription = SavedRecipeDescription( - id = 1L, + id = recipeId, title = title, imageUri = "", description = introduction, diff --git a/android/app/src/main/java/net/pengcook/android/domain/model/recipemaking/RecipeCreation.kt b/android/app/src/main/java/net/pengcook/android/domain/model/recipemaking/RecipeCreation.kt index 9c40c681..df15c7f0 100644 --- a/android/app/src/main/java/net/pengcook/android/domain/model/recipemaking/RecipeCreation.kt +++ b/android/app/src/main/java/net/pengcook/android/domain/model/recipemaking/RecipeCreation.kt @@ -4,6 +4,7 @@ import net.pengcook.android.presentation.core.model.Ingredient import net.pengcook.android.presentation.core.model.RecipeStepMaking data class RecipeCreation( + val recipeId: Long = 1L, val title: String, val introduction: String, val cookingTime: String, diff --git a/android/app/src/main/java/net/pengcook/android/presentation/edit/EditRecipeViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/edit/EditRecipeViewModel.kt index 97ebdf69..70396535 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/edit/EditRecipeViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/edit/EditRecipeViewModel.kt @@ -95,7 +95,10 @@ class EditRecipeViewModel minuteContent.value = recipe.cookingTime.split(":")[1] secondContent.value = recipe.cookingTime.split(":")[2] _thumbnailUri.value = Uri.parse(recipe.thumbnail) - thumbnailTitle = recipe.thumbnail + thumbnailTitle = recipe.thumbnail.split("/").lastOrNull() ?: run { + _uiEvent.value = Event(EditRecipeEvent.RecipePostFailure) + return@launch + } } } } @@ -283,6 +286,8 @@ class EditRecipeViewModel } override fun onConfirm() { + val steps = EditRecipeRepository.fetchAllSavedRecipeData().getOrNull()?.steps + val recipeCreation = RecipeCreation( title = titleContent.value ?: "", @@ -302,16 +307,16 @@ class EditRecipeViewModel ) } ?: emptyList(), steps = - currentStepImages.value?.map { + steps?.map { RecipeStepMaking( - stepId = it.itemId.toLong(), + stepId = it.stepId, recipeId = recipeId, description = it.description, - image = it.imageTitle, + image = it.image, sequence = it.sequence, - imageUri = it.uri.toString(), + imageUri = it.imageUri, cookingTime = it.cookingTime, - imageUploaded = it.uploaded, + imageUploaded = it.imageUploaded, ) } ?: emptyList(), categories = @@ -332,10 +337,8 @@ class EditRecipeViewModel return } - val entireData = EditRecipeRepository.fetchAllSavedRecipeData().getOrNull() - if (entireData == null) { - return - } + val entireData = EditRecipeRepository.fetchAllSavedRecipeData().getOrNull() ?: return + println(entireData.steps) val changedRecipe = ChangedRecipe( title = entireData.title, @@ -431,7 +434,7 @@ class EditRecipeViewModel private fun saveRecipeDescription() { val recipeDescription = RecipeDescription( - recipeDescriptionId = recipeId ?: return, + recipeDescriptionId = recipeId, categories = categoryContent.value ?.split(SEPARATOR_INGREDIENTS) @@ -450,6 +453,7 @@ class EditRecipeViewModel val recipeCreation = RecipeCreation( + recipeId = recipeId, title = recipeDescription.title, introduction = recipeDescription.description, cookingTime = recipeDescription.cookingTime, diff --git a/android/app/src/main/java/net/pengcook/android/presentation/edit/step/EditStepsViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/edit/step/EditStepsViewModel.kt index 2f09df03..c400d919 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/edit/step/EditStepsViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/edit/step/EditStepsViewModel.kt @@ -37,6 +37,7 @@ class EditStepsViewModel : fun saveData() { val data = steps.value + println(data) if (data == null) { _uiEvent.value = EditStepsEvent.OnSaveFailure @@ -47,6 +48,7 @@ class EditStepsViewModel : fun exit() { val data = steps.value + println(data) if (data == null) { _uiEvent.value = EditStepsEvent.OnSaveFailure @@ -68,12 +70,17 @@ class EditStepsViewModel : } override fun navigationAction() { + exit() + println("data : ${EditRecipeRepository.fetchAllSavedRecipeData().getOrNull()}") + _uiEvent.value = EditStepsEvent.NavigationEvent } override fun customAction() { - _uiEvent.value = EditStepsEvent.TempSaveEvent saveData() + println("data : ${EditRecipeRepository.fetchAllSavedRecipeData().getOrNull()}") + + _uiEvent.value = EditStepsEvent.TempSaveEvent } override fun onDescriptionChanged( diff --git a/android/app/src/main/java/net/pengcook/android/presentation/making/step/StepMakingViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/making/step/StepMakingViewModel.kt index 7ced4611..9648de7d 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/making/step/StepMakingViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/making/step/StepMakingViewModel.kt @@ -251,6 +251,7 @@ class StepMakingViewModel private suspend fun recipeCreation(): RecipeCreation? { val recipeData = makingRecipeRepository.fetchTotalRecipeData().getOrNull() ?: return null return RecipeCreation( + recipeId = recipeId, title = recipeData.title, thumbnail = recipeData.thumbnail, cookingTime = recipeData.cookingTime,