-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,912 additions
and
30 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
.../app/src/main/java/net/pengcook/android/data/datasource/edit/EditRecipeCacheDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package net.pengcook.android.data.datasource.edit | ||
|
||
object EditRecipeCacheDataSource { | ||
private var savedRecipeDescription: SavedRecipeDescription? = null | ||
|
||
var savedRecipeSteps: List<SavedRecipeSteps> = listOf() | ||
private set | ||
|
||
fun fetchSavedRecipeDescription(): SavedRecipeDescription { | ||
val data = savedRecipeDescription | ||
check(data != null) { "Saved recipe description is not available" } | ||
return data | ||
} | ||
|
||
fun saveRecipeDescription(changedRecipeDescription: SavedRecipeDescription) { | ||
this.savedRecipeDescription = changedRecipeDescription | ||
} | ||
|
||
fun clearSavedRecipeDescription() { | ||
savedRecipeDescription = null | ||
} | ||
|
||
fun saveRecipeSteps(savedRecipeSteps: List<SavedRecipeSteps>) { | ||
this.savedRecipeSteps = savedRecipeSteps | ||
} | ||
|
||
fun clearSavedRecipeSteps() { | ||
savedRecipeSteps = emptyList() | ||
} | ||
} | ||
|
||
data class SavedRecipeDescription( | ||
val id: Long, | ||
val title: String, | ||
val imageUri: String, | ||
val description: String, | ||
val cookingTime: String, | ||
val categories: List<String>, | ||
val ingredients: List<SavedIngredient>, | ||
val difficulty: Int, | ||
val thumbnail: String, | ||
) | ||
|
||
data class SavedIngredient( | ||
val name: String, | ||
val requirement: String = "REQUIRED", | ||
val substitutions: List<String> = emptyList(), | ||
) | ||
|
||
data class SavedRecipeSteps( | ||
val sequence: Int, | ||
val imageUri: String?, | ||
val imageTitle: String?, | ||
val cookingTime: String?, | ||
val description: String?, | ||
val imageUploaded: Boolean, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
android/app/src/main/java/net/pengcook/android/data/model/feed/item/RecipeEditRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.pengcook.android.data.model.feed.item | ||
|
||
import net.pengcook.android.data.model.makingrecipe.request.IngredientRequest | ||
import net.pengcook.android.data.model.makingrecipe.request.RecipeStepRequest | ||
|
||
data class RecipeEditRequest( | ||
val title: String, | ||
val cookingTime: String, | ||
val thumbnail: String, | ||
val difficulty: Int, | ||
val description: String, | ||
val categories: List<String>, | ||
val ingredients: List<IngredientRequest>, | ||
val recipeSteps: List<RecipeStepRequest>, | ||
) |
2 changes: 1 addition & 1 deletion
2
android/app/src/main/java/net/pengcook/android/data/model/step/RecipeStepResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
android/app/src/main/java/net/pengcook/android/data/model/step/request/RecipeStepRequest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
android/app/src/main/java/net/pengcook/android/data/remote/api/StepMakingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
android/app/src/main/java/net/pengcook/android/data/repository/edit/EditRecipeRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package net.pengcook.android.data.repository.edit | ||
|
||
import net.pengcook.android.data.datasource.edit.EditRecipeCacheDataSource | ||
import net.pengcook.android.data.datasource.edit.SavedIngredient | ||
import net.pengcook.android.data.datasource.edit.SavedRecipeDescription | ||
import net.pengcook.android.data.datasource.edit.SavedRecipeSteps | ||
import net.pengcook.android.domain.model.recipemaking.RecipeCreation | ||
import net.pengcook.android.presentation.core.model.Ingredient | ||
import net.pengcook.android.presentation.core.model.RecipeStepMaking | ||
|
||
object EditRecipeRepository { | ||
fun saveRecipe(recipeCreation: RecipeCreation): Result<Unit> = | ||
runCatching { | ||
EditRecipeCacheDataSource.saveRecipeDescription(recipeCreation.toSavedRecipeDescription()) | ||
EditRecipeCacheDataSource.saveRecipeSteps(recipeCreation.steps.map { it.toSavedRecipeStep() }) | ||
} | ||
|
||
fun saveRecipeSteps(recipeSteps: List<RecipeStepMaking>): Result<Unit> = | ||
runCatching { | ||
EditRecipeCacheDataSource.saveRecipeSteps(recipeSteps.map { it.toSavedRecipeStep() }) | ||
} | ||
|
||
fun saveRecipeDescription(recipeDescription: RecipeCreation): Result<Unit> = | ||
runCatching { | ||
EditRecipeCacheDataSource.saveRecipeDescription(recipeDescription.toSavedRecipeDescription()) | ||
} | ||
|
||
fun fetchAllSavedRecipeData(): Result<RecipeCreation> = | ||
runCatching { | ||
val description = EditRecipeCacheDataSource.fetchSavedRecipeDescription() | ||
val steps = EditRecipeCacheDataSource.savedRecipeSteps | ||
println("description: $description") | ||
println("steps: $steps") | ||
RecipeCreation( | ||
title = description.title, | ||
introduction = description.description, | ||
cookingTime = description.cookingTime, | ||
difficulty = description.difficulty, | ||
ingredients = | ||
description.ingredients.map { | ||
Ingredient( | ||
ingredientId = 1L, | ||
ingredientName = it.name, | ||
requirement = it.requirement, | ||
) | ||
}, | ||
categories = description.categories, | ||
thumbnail = description.thumbnail, | ||
steps = | ||
steps.mapIndexed { index, it -> | ||
RecipeStepMaking( | ||
stepId = index.toLong(), | ||
recipeId = description.id, | ||
description = it.description ?: "", | ||
image = it.imageUri ?: "", | ||
sequence = it.sequence, | ||
imageUri = it.imageUri ?: "", | ||
cookingTime = it.cookingTime ?: "00:00:00", | ||
imageUploaded = it.imageUploaded, | ||
) | ||
}, | ||
) | ||
} | ||
|
||
// fun fetchSavedRecipeSteps(): Result<List<RecipeStep>> = runCatching { | ||
// EditRecipeCacheDataSource.savedRecipeSteps.map { | ||
// RecipeStep( | ||
// stepId = it.sequence.toLong(), | ||
// description = it.description ?: "", | ||
// image = it.imageUri ?: "", | ||
// sequence = it.sequence, | ||
// image = it.imageUri ?: "", | ||
// cookingTime = it.cookingTime ?: "00:00:00", | ||
// imageUploaded = it.imageUploaded, | ||
// ) | ||
// } | ||
// } | ||
// | ||
|
||
fun clearSavedRecipeData() { | ||
EditRecipeCacheDataSource.clearSavedRecipeDescription() | ||
EditRecipeCacheDataSource.clearSavedRecipeSteps() | ||
} | ||
|
||
private fun RecipeCreation.toSavedRecipeDescription(): SavedRecipeDescription = | ||
SavedRecipeDescription( | ||
id = 1L, | ||
title = title, | ||
imageUri = "", | ||
description = introduction, | ||
cookingTime = cookingTime, | ||
categories = categories, | ||
ingredients = | ||
ingredients.map { | ||
SavedIngredient( | ||
name = it.ingredientName, | ||
) | ||
}, | ||
difficulty = difficulty, | ||
thumbnail = thumbnail, | ||
) | ||
|
||
private fun RecipeStepMaking.toSavedRecipeStep(): SavedRecipeSteps = | ||
SavedRecipeSteps( | ||
sequence = sequence, | ||
imageUri = imageUri, | ||
imageTitle = "", | ||
cookingTime = cookingTime, | ||
description = description, | ||
imageUploaded = imageUploaded, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/net/pengcook/android/presentation/core/model/ChangedRecipe.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.pengcook.android.presentation.core.model | ||
|
||
data class ChangedRecipe( | ||
val title: String, | ||
val cookingTime: String, | ||
val thumbnail: String, | ||
val difficulty: Int, | ||
val description: String, | ||
val categories: List<String>, | ||
val ingredients: List<Ingredient>, | ||
val recipeSteps: List<RecipeStep>, | ||
) |
Oops, something went wrong.