Compare commits
No commits in common. "dc7e94b37ba2a5475c0ddfbda6f7dccb7600686d" and "f9296f05c1a2b685210574fafddcecc6c399d1d7" have entirely different histories.
dc7e94b37b
...
f9296f05c1
@ -1,7 +1,6 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
<JetCodeStyleSettings>
|
<JetCodeStyleSettings>
|
||||||
<option name="ALLOW_TRAILING_COMMA" value="true" />
|
|
||||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
</JetCodeStyleSettings>
|
</JetCodeStyleSettings>
|
||||||
<codeStyleSettings language="XML">
|
<codeStyleSettings language="XML">
|
||||||
|
@ -3,7 +3,7 @@ package tech.mercantec.easyeat.helpers
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import tech.mercantec.easyeat.models.Recipe
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LoginRequest(val emailUsr: String, val password: String)
|
data class LoginRequest(val emailUsr: String, val password: String)
|
||||||
|
|
||||||
@ -109,12 +109,3 @@ fun changePassword(ctx: Context, oldPassword: String, newPassword: String) {
|
|||||||
|
|
||||||
return requestJson<ChangePasswordRequest, Unit>(ctx, "PUT", "/api/User/change-password", request)
|
return requestJson<ChangePasswordRequest, Unit>(ctx, "PUT", "/api/User/change-password", request)
|
||||||
}
|
}
|
||||||
@Serializable
|
|
||||||
data class CreateRecipeRequest(val recipe: Recipe)
|
|
||||||
|
|
||||||
fun createRecipe(ctx: Context, recipe: Recipe) {
|
|
||||||
val request = CreateRecipeRequest(recipe)
|
|
||||||
|
|
||||||
return requestJson<CreateRecipeRequest, Unit>(ctx, "POST", "/api/recipe/create", request)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package tech.mercantec.easyeat.models
|
||||||
|
|
||||||
|
data class Ingredient(
|
||||||
|
val Amount: Int,
|
||||||
|
val Unit: String,
|
||||||
|
val Element: String
|
||||||
|
)
|
@ -1,24 +0,0 @@
|
|||||||
package tech.mercantec.easyeat.models
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Recipe(
|
|
||||||
val name: String,
|
|
||||||
val description: String,
|
|
||||||
val directions: List<Direction>,
|
|
||||||
val ingredients: List<Ingredient>
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Direction(
|
|
||||||
val instructions: String
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Ingredient(
|
|
||||||
val amount: Double?,
|
|
||||||
val unit: String?,
|
|
||||||
val name: String
|
|
||||||
)
|
|
@ -1,7 +1,5 @@
|
|||||||
package tech.mercantec.easyeat.ui.dishes
|
package tech.mercantec.easyeat.ui.dishes
|
||||||
|
|
||||||
import android.app.ProgressDialog
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@ -11,18 +9,9 @@ import android.widget.EditText
|
|||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.Spinner
|
import android.widget.Spinner
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContentProviderCompat.requireContext
|
|
||||||
import tech.mercantec.easyeat.R
|
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.Direction
|
|
||||||
import tech.mercantec.easyeat.models.Ingredient
|
import tech.mercantec.easyeat.models.Ingredient
|
||||||
import tech.mercantec.easyeat.models.Recipe
|
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
class CreateDishActivity : AppCompatActivity() {
|
class CreateDishActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@ -46,61 +35,16 @@ class CreateDishActivity : AppCompatActivity() {
|
|||||||
val saveButton: Button = findViewById(R.id.saveDishButton)
|
val saveButton: Button = findViewById(R.id.saveDishButton)
|
||||||
saveButton.setOnClickListener {
|
saveButton.setOnClickListener {
|
||||||
val ingredientList = collectIngredients()
|
val ingredientList = collectIngredients()
|
||||||
|
|
||||||
|
val name = findViewById<EditText>(R.id.dishName).text.toString().trim()
|
||||||
|
val description = findViewById<EditText>(R.id.dishDescription).text.toString().trim()
|
||||||
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
|
// Debug/log example
|
||||||
.split("\n")
|
for (ingredient in ingredientList) {
|
||||||
.map { line -> line.trim() }
|
Log.d("INGREDIENT", "Name: ${ingredient.Element}, Amount: ${ingredient.Amount}, Unit: ${ingredient.Unit}")
|
||||||
.filter { it.isNotEmpty() }
|
|
||||||
.map { line -> Direction(instructions = line) }
|
|
||||||
|
|
||||||
val recipe = Recipe(
|
|
||||||
name = findViewById<EditText>(R.id.dishName).text.toString().trim(),
|
|
||||||
description = findViewById<EditText>(R.id.dishDescription).text.toString().trim(),
|
|
||||||
directions = directions,
|
|
||||||
ingredients = ingredientList
|
|
||||||
)
|
|
||||||
|
|
||||||
Log.i("recipe name:", recipe.name)
|
|
||||||
Log.i("recipe name:", recipe.description)
|
|
||||||
for (x in recipe.directions) {
|
|
||||||
Log.i("recipe name:", x.instructions)
|
|
||||||
}
|
|
||||||
for(x in recipe.ingredients){
|
|
||||||
Log.i("recipe name:", x.name)
|
|
||||||
Log.i("recipe name:", x.amount.toString())
|
|
||||||
Log.i("recipe name:", x.unit.toString())
|
|
||||||
}
|
|
||||||
val progressDialog = ProgressDialog(this)
|
|
||||||
progressDialog.setMessage("Loading...")
|
|
||||||
progressDialog.show()
|
|
||||||
thread {
|
|
||||||
try {
|
|
||||||
createRecipe(this, recipe)
|
|
||||||
} catch (e: ApiRequestException) {
|
|
||||||
runOnUiThread {
|
|
||||||
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
return@thread
|
|
||||||
} finally {
|
|
||||||
runOnUiThread {
|
|
||||||
progressDialog.hide()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread {
|
|
||||||
Toast.makeText(this, "Password changed successfully", Toast.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addIngredientRow() {
|
private fun addIngredientRow() {
|
||||||
@ -140,7 +84,7 @@ class CreateDishActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// Optional: Only add non-empty rows
|
// Optional: Only add non-empty rows
|
||||||
if (element.isNotEmpty() && amount.isNotEmpty()) {
|
if (element.isNotEmpty() && amount.isNotEmpty()) {
|
||||||
ingredients.add(Ingredient(name = element, amount = amount.toDouble(), unit = unit))
|
ingredients.add(Ingredient(Element = element, Amount = amount.toInt(), Unit = unit))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ namespace API.Controllers
|
|||||||
/// <param name="recipe">The recipe to be added</param>
|
/// <param name="recipe">The recipe to be added</param>
|
||||||
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
|
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPost("create")]
|
[HttpPost("create/{RecipesId}")]
|
||||||
public async Task<IActionResult> CreateRecipe([FromBody] RecipeDTO recipe)
|
public async Task<IActionResult> CreateRecipe([FromBody] RecipeDTO recipe)
|
||||||
{
|
{
|
||||||
var claims = HttpContext.User.Claims;
|
var claims = HttpContext.User.Claims;
|
||||||
|
Loading…
Reference in New Issue
Block a user