diff --git a/app/app/src/main/AndroidManifest.xml b/app/app/src/main/AndroidManifest.xml index 10e464a..e1e0150 100644 --- a/app/app/src/main/AndroidManifest.xml +++ b/app/app/src/main/AndroidManifest.xml @@ -45,7 +45,7 @@ android:exported="false" /> (ctx, "POST", "/api/User/login", request) - with (ctx.getSharedPreferences("easyeat", Context.MODE_PRIVATE).edit()) { + with(ctx.getSharedPreferences("easyeat", Context.MODE_PRIVATE).edit()) { putInt("user-id", response.id) putString("username", response.userName) putString("auth-token", response.token) @@ -30,7 +25,7 @@ fun login(ctx: Context, email: String, password: String) { } fun logout(ctx: Context) { - with (ctx.getSharedPreferences("easyeat", Context.MODE_PRIVATE).edit()) { + with(ctx.getSharedPreferences("easyeat", Context.MODE_PRIVATE).edit()) { remove("user-id") remove("username") remove("auth-token") @@ -114,26 +109,3 @@ fun changePassword(ctx: Context, oldPassword: String, newPassword: String) { return requestJson(ctx, "PUT", "/api/User/change-password", request) } - -@Serializable -data class CreateRecipeRequest(val name: String, val description: String, val directions: List, val ingredients: List) - -fun createRecipe(ctx: Context, recipe: CreateRecipe) { - val request = CreateRecipeRequest(recipe.name, recipe.description, recipe.directions, recipe.ingredients) - - requestJson(ctx, "POST", "/api/recipe/create", request) -} - -@Serializable -data class GetAllRecipesResponse(val id: Int, val name: String, val description: String) - -fun getAllRecipies(ctx: Context): List { - return requestJson>(ctx, "GET", "/api/Recipe/getall", null) -} - -@Serializable -data class RecipeDetailsResponse(val id: Int, val name: String, val description: String, val directions: List, val ingredients: List) - -fun getRecipeDetails(ctx: Context, id: Int): RecipeDetailsResponse { - return requestJson(ctx, "GET", "/api/Recipe/get/$id", null) -} 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 index e0aa866..4a7a599 100644 --- a/app/app/src/main/java/tech/mercantec/easyeat/helpers/dishes.kt +++ b/app/app/src/main/java/tech/mercantec/easyeat/helpers/dishes.kt @@ -2,6 +2,7 @@ package tech.mercantec.easyeat.helpers import android.content.Context import kotlinx.serialization.Serializable +import tech.mercantec.easyeat.models.Ingredient import tech.mercantec.easyeat.models.Recipe @Serializable @@ -10,3 +11,21 @@ data class GenerateRecipeRequest(val dish: String, val language: String, val num fun generateRecipeWithAI(ctx: Context, title: String, language: String): Recipe { return requestJson(ctx, "POST", "/api/Recipe/chatbot", GenerateRecipeRequest(title, language, 1, arrayOf())) } + +fun createRecipe(ctx: Context, recipe: Recipe) { + requestJson(ctx, "POST", "/api/recipe/create", recipe) +} + +@Serializable +data class GetAllRecipesResponse(val id: Int, val name: String, val description: String) + +fun getAllRecipes(ctx: Context): List { + return requestJson>(ctx, "GET", "/api/Recipe/getall", null) +} + +@Serializable +data class RecipeDetailsResponse(val id: Int, val name: String, val description: String, val directions: List, val ingredients: List) + +fun getRecipeDetails(ctx: Context, id: Int): RecipeDetailsResponse { + return requestJson(ctx, "GET", "/api/Recipe/get/$id", null) +} diff --git a/app/app/src/main/java/tech/mercantec/easyeat/models/CreateRecipe.kt b/app/app/src/main/java/tech/mercantec/easyeat/models/CreateRecipe.kt deleted file mode 100644 index 782f449..0000000 --- a/app/app/src/main/java/tech/mercantec/easyeat/models/CreateRecipe.kt +++ /dev/null @@ -1,24 +0,0 @@ -package tech.mercantec.easyeat.models - -import kotlinx.serialization.Serializable - -@Serializable -data class CreateRecipe( - val name: String, - val description: String, - val directions: List, - val ingredients: List -) - -@Serializable -data class CreateDirection( - val instructions: String -) - - -@Serializable -data class CreateIngredient( - val amount: Double?, - val unit: String?, - val name: String -) \ No newline at end of file diff --git a/app/app/src/main/java/tech/mercantec/easyeat/models/recipe.kt b/app/app/src/main/java/tech/mercantec/easyeat/models/recipe.kt index 86e5796..2ee35ed 100644 --- a/app/app/src/main/java/tech/mercantec/easyeat/models/recipe.kt +++ b/app/app/src/main/java/tech/mercantec/easyeat/models/recipe.kt @@ -2,10 +2,9 @@ package tech.mercantec.easyeat.models import kotlinx.serialization.Serializable - @Serializable data class Recipe( - val id: Int, + val id: Int? = null, val name: String, val description: String, val directions: List, @@ -14,7 +13,7 @@ data class Recipe( @Serializable data class Ingredient( - val id: Int, + val id: Int? = null, val amount: Double?, val unit: String?, val name: String diff --git a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishActivity.kt b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishActivity.kt index 2ece5a7..b5cf99f 100644 --- a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishActivity.kt +++ b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/CreateDishActivity.kt @@ -2,9 +2,7 @@ package tech.mercantec.easyeat.ui.dishes import android.app.Activity import android.app.ProgressDialog -import android.content.Context import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.widget.ArrayAdapter import android.widget.Button @@ -14,15 +12,11 @@ import android.widget.LinearLayout import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.ContentProviderCompat.requireContext import tech.mercantec.easyeat.R import tech.mercantec.easyeat.helpers.ApiRequestException -import tech.mercantec.easyeat.helpers.changePassword import tech.mercantec.easyeat.helpers.createRecipe -import tech.mercantec.easyeat.helpers.request -import tech.mercantec.easyeat.models.CreateDirection -import tech.mercantec.easyeat.models.CreateIngredient -import tech.mercantec.easyeat.models.CreateRecipe +import tech.mercantec.easyeat.models.Ingredient +import tech.mercantec.easyeat.models.Recipe import kotlin.concurrent.thread class CreateDishActivity : AppCompatActivity() { @@ -53,7 +47,7 @@ class CreateDishActivity : AppCompatActivity() { .map { line -> line.trim() } .filter { it.isNotEmpty() } - val recipe = CreateRecipe( + val recipe = Recipe( name = findViewById(R.id.dishName).text.toString().trim(), description = findViewById(R.id.dishDescription).text.toString().trim(), directions = directions, @@ -107,8 +101,8 @@ class CreateDishActivity : AppCompatActivity() { ingredientContainer.addView(ingredientRow) } - private fun collectIngredients(): List { - val ingredients = mutableListOf() + private fun collectIngredients(): List { + val ingredients = mutableListOf() for (i in 0 until ingredientContainer.childCount) { val ingredientView = ingredientContainer.getChildAt(i) @@ -125,7 +119,7 @@ class CreateDishActivity : AppCompatActivity() { // Optional: Only add non-empty rows if (element.isNotEmpty() && amount.isNotEmpty()) { - ingredients.add(CreateIngredient(name = element, amount = amount.toDouble(), unit = unit)) + ingredients.add(Ingredient(name = element, amount = amount.toDouble(), unit = unit)) } } diff --git a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishesFragment.kt b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishesFragment.kt index 4e1a301..93e06c7 100644 --- a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishesFragment.kt +++ b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishesFragment.kt @@ -15,7 +15,7 @@ import tech.mercantec.easyeat.R import tech.mercantec.easyeat.databinding.FragmentDishesBinding import tech.mercantec.easyeat.helpers.ApiRequestException import tech.mercantec.easyeat.helpers.GetAllRecipesResponse -import tech.mercantec.easyeat.helpers.getAllRecipies +import tech.mercantec.easyeat.helpers.getAllRecipes import tech.mercantec.easyeat.models.DishListItem import kotlin.concurrent.thread @@ -52,7 +52,7 @@ class DishesFragment : Fragment() { } dialogView.findViewById