From df7d5f9695101496393118b8f02af7de0965b425 Mon Sep 17 00:00:00 2001 From: Jeas0001 Date: Tue, 13 May 2025 10:31:37 +0200 Subject: [PATCH 1/4] Changed directions in recipedto to a string array instead of an object array Only the dto was changed --- backend/API/BusinessLogic/RecipeLogic.cs | 4 ++-- backend/API/Models/RecipeModels/DirectionsDTO.cs | 7 ------- backend/API/Models/RecipeModels/RecipeDTO.cs | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) delete mode 100644 backend/API/Models/RecipeModels/DirectionsDTO.cs diff --git a/backend/API/BusinessLogic/RecipeLogic.cs b/backend/API/BusinessLogic/RecipeLogic.cs index 48aaa3f..8e9bb4d 100644 --- a/backend/API/BusinessLogic/RecipeLogic.cs +++ b/backend/API/BusinessLogic/RecipeLogic.cs @@ -71,7 +71,7 @@ namespace API.BusinessLogic foreach (var item in recipe.Directions) { Directions directions = new Directions(); - directions.Instruktions = item.Instructions; + directions.Instruktions = item; dish.Directions.Add(directions); } @@ -112,7 +112,7 @@ namespace API.BusinessLogic foreach (var item in recipe.Directions) { Directions directions = new Directions(); - directions.Instruktions = item.Instructions; + directions.Instruktions = item; dish.Directions.Add(directions); } diff --git a/backend/API/Models/RecipeModels/DirectionsDTO.cs b/backend/API/Models/RecipeModels/DirectionsDTO.cs deleted file mode 100644 index 9cc9c85..0000000 --- a/backend/API/Models/RecipeModels/DirectionsDTO.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace API.Models.RecipeModels -{ - public class DirectionsDTO - { - public string Instructions { get; set; } - } -} diff --git a/backend/API/Models/RecipeModels/RecipeDTO.cs b/backend/API/Models/RecipeModels/RecipeDTO.cs index 289fe2e..d54f1f4 100644 --- a/backend/API/Models/RecipeModels/RecipeDTO.cs +++ b/backend/API/Models/RecipeModels/RecipeDTO.cs @@ -6,7 +6,7 @@ public string Description { get; set; } - public List Directions { get; set; } + public List Directions { get; set; } public List Ingredients { get; set; } } From f0e7e67d771dd04b0f19ce8175bf7c6067cbcaad Mon Sep 17 00:00:00 2001 From: Reimar Date: Tue, 13 May 2025 09:51:20 +0200 Subject: [PATCH 2/4] Allow generating recipes with AI --- .../tech/mercantec/easyeat/helpers/dishes.kt | 15 +++++++ .../easyeat/ui/dishes/CreateDishAIActivity.kt | 37 +++++++++++++++- .../ui/shopping_list/ShoppingItemAdapter.kt | 8 ++-- .../main/res/layout/create_dish_ai_form.xml | 44 +++++++++++++++---- app/app/src/main/res/values/strings.xml | 3 ++ 5 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 app/app/src/main/java/tech/mercantec/easyeat/helpers/dishes.kt diff --git a/app/app/src/main/java/tech/mercantec/easyeat/helpers/dishes.kt b/app/app/src/main/java/tech/mercantec/easyeat/helpers/dishes.kt new file mode 100644 index 0000000..d907915 --- /dev/null +++ b/app/app/src/main/java/tech/mercantec/easyeat/helpers/dishes.kt @@ -0,0 +1,15 @@ +package tech.mercantec.easyeat.helpers + +import android.content.Context +import kotlinx.serialization.Serializable +import tech.mercantec.easyeat.models.Ingredient + +@Serializable +data class GenerateRecipeRequest(val dish: String, val language: String, val numberOfRecipes: Int, val allergi: Array) + +@Serializable +data class GenerateRecipeResponse(val name: String, val description: String, val directions: Array, val ingredients: Array) + +fun generateRecipeWithAI(ctx: Context, title: String, language: String): GenerateRecipeResponse { + return requestJson(ctx, "POST", "/api/Recipe/chatbot", GenerateRecipeRequest(title, language, 1, arrayOf())) +} diff --git a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishAIActivity.kt b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishAIActivity.kt index 82133f6..fcf4bdc 100644 --- a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishAIActivity.kt +++ b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishAIActivity.kt @@ -1,16 +1,49 @@ package tech.mercantec.easyeat.ui.dishes +import android.app.ProgressDialog import android.os.Bundle +import android.widget.Button +import android.widget.EditText import android.widget.LinearLayout +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import tech.mercantec.easyeat.R +import tech.mercantec.easyeat.helpers.ApiRequestException +import tech.mercantec.easyeat.helpers.GenerateRecipeResponse +import tech.mercantec.easyeat.helpers.generateRecipeWithAI +import java.util.Locale +import kotlin.concurrent.thread class CreateDishAIActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.create_dish_ai_form) - } + findViewById