Use string array for directions in recipes
This commit is contained in:
parent
f0e7e67d77
commit
59af36b3f2
@ -2,14 +2,11 @@ package tech.mercantec.easyeat.helpers
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import tech.mercantec.easyeat.models.Ingredient
|
import tech.mercantec.easyeat.models.Recipe
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GenerateRecipeRequest(val dish: String, val language: String, val numberOfRecipes: Int, val allergi: Array<String>)
|
data class GenerateRecipeRequest(val dish: String, val language: String, val numberOfRecipes: Int, val allergi: Array<String>)
|
||||||
|
|
||||||
@Serializable
|
fun generateRecipeWithAI(ctx: Context, title: String, language: String): Recipe {
|
||||||
data class GenerateRecipeResponse(val name: String, val description: String, val directions: Array<String>, val ingredients: Array<Ingredient>)
|
return requestJson<GenerateRecipeRequest, Recipe>(ctx, "POST", "/api/Recipe/chatbot", GenerateRecipeRequest(title, language, 1, arrayOf()))
|
||||||
|
|
||||||
fun generateRecipeWithAI(ctx: Context, title: String, language: String): GenerateRecipeResponse {
|
|
||||||
return requestJson<GenerateRecipeRequest, GenerateRecipeResponse>(ctx, "POST", "/api/Recipe/chatbot", GenerateRecipeRequest(title, language, 1, arrayOf()))
|
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,10 @@ import kotlinx.serialization.Serializable
|
|||||||
data class Recipe(
|
data class Recipe(
|
||||||
val name: String,
|
val name: String,
|
||||||
val description: String,
|
val description: String,
|
||||||
val directions: List<Direction>,
|
val directions: List<String>,
|
||||||
val ingredients: List<Ingredient>
|
val ingredients: List<Ingredient>
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Direction(
|
|
||||||
val instructions: String
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Ingredient(
|
data class Ingredient(
|
||||||
val amount: Double?,
|
val amount: Double?,
|
||||||
|
@ -48,11 +48,10 @@ class CreateDishActivity : AppCompatActivity() {
|
|||||||
saveButton.setOnClickListener {
|
saveButton.setOnClickListener {
|
||||||
val ingredientList = collectIngredients()
|
val ingredientList = collectIngredients()
|
||||||
val instructions = findViewById<EditText>(R.id.instructions).text.toString().trim()
|
val instructions = findViewById<EditText>(R.id.instructions).text.toString().trim()
|
||||||
val directions: List<Direction> = instructions
|
val directions: List<String> = instructions
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map { line -> line.trim() }
|
.map { line -> line.trim() }
|
||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
.map { line -> Direction(instructions = line) }
|
|
||||||
|
|
||||||
val recipe = Recipe(
|
val recipe = Recipe(
|
||||||
name = findViewById<EditText>(R.id.dishName).text.toString().trim(),
|
name = findViewById<EditText>(R.id.dishName).text.toString().trim(),
|
||||||
@ -61,7 +60,6 @@ class CreateDishActivity : AppCompatActivity() {
|
|||||||
ingredients = ingredientList
|
ingredients = ingredientList
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
val progressDialog = ProgressDialog(this)
|
val progressDialog = ProgressDialog(this)
|
||||||
progressDialog.setMessage("Loading...")
|
progressDialog.setMessage("Loading...")
|
||||||
progressDialog.show()
|
progressDialog.show()
|
||||||
|
Loading…
Reference in New Issue
Block a user