made new getallrecipedto and return on getallrecipe
This commit is contained in:
parent
3b01992eed
commit
5c1a569906
@ -110,6 +110,7 @@ fun changePassword(ctx: Context, oldPassword: String, newPassword: String) {
|
||||
|
||||
return requestJson<ChangePasswordRequest, Unit>(ctx, "PUT", "/api/User/change-password", request)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CreateRecipeRequest(val recipe: Recipe)
|
||||
|
||||
|
@ -2,6 +2,7 @@ package tech.mercantec.easyeat.ui.dishes
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -12,8 +13,13 @@ import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import tech.mercantec.easyeat.R
|
||||
import tech.mercantec.easyeat.databinding.FragmentDishesBinding
|
||||
import tech.mercantec.easyeat.helpers.ApiRequestException
|
||||
import tech.mercantec.easyeat.helpers.RecipeResponse
|
||||
import tech.mercantec.easyeat.helpers.getRecipies
|
||||
import tech.mercantec.easyeat.helpers.login
|
||||
import tech.mercantec.easyeat.models.DishListItem
|
||||
import tech.mercantec.easyeat.ui.MainActivity
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class DishesFragment : Fragment() {
|
||||
|
||||
@ -31,20 +37,41 @@ class DishesFragment : Fragment() {
|
||||
_binding = FragmentDishesBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
lifecycleScope.launch {
|
||||
|
||||
thread {
|
||||
val recipes: List<RecipeResponse>
|
||||
try {
|
||||
val recipes = getRecipies(requireContext()) // this is now suspend
|
||||
val dishes = recipes.map {
|
||||
DishListItem(it.name, it.description) // assuming description is the main ingredient and no price
|
||||
recipes = getRecipies(requireContext())
|
||||
} catch (e: ApiRequestException) {
|
||||
activity?.runOnUiThread {
|
||||
Toast.makeText(requireContext(), e.message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
val adapter = DishAdapter(requireContext(), dishes)
|
||||
binding.dishesList.adapter = adapter
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(requireContext(), "Failed to load recipes: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
return@thread
|
||||
}
|
||||
val dishes = recipes.map {
|
||||
DishListItem(
|
||||
it.name,
|
||||
it.description
|
||||
) // assuming description is the main ingredient and no price
|
||||
}
|
||||
}
|
||||
|
||||
// lifecycleScope.launch {
|
||||
// try {
|
||||
// val recipes = getRecipies(requireContext()) // this is now suspend
|
||||
// val dishes = recipes.map {
|
||||
// DishListItem(it.name, it.description) // assuming description is the main ingredient and no price
|
||||
// }
|
||||
//
|
||||
// val adapter = DishAdapter(requireContext(), dishes)
|
||||
// binding.dishesList.adapter = adapter
|
||||
// } catch (e: Exception) {
|
||||
// Log.i("nice", e.message.toString())
|
||||
// Toast.makeText(requireContext(), "Failed to load recipes: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
binding.addDish.setOnClickListener {
|
||||
val dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.create_dish_modal_dialog, null)
|
||||
|
@ -23,7 +23,14 @@ namespace API.BusinessLogic
|
||||
var recipes = await _dbAccess.ReadRecipes(userId);
|
||||
if (recipes == null || recipes.Count == 0) { return new ConflictObjectResult(new { message = "Could not find any recipes" }); }
|
||||
|
||||
return new OkObjectResult(recipes);
|
||||
var recipeDtos = recipes.Select(r => new GetAllRecipesDTO
|
||||
{
|
||||
Id = r.Id,
|
||||
Name = r.Name,
|
||||
Description = r.Description
|
||||
}).ToList();
|
||||
|
||||
return new OkObjectResult(recipeDtos);
|
||||
}
|
||||
|
||||
// Gets a specifik with recipe with the ingredient and directions
|
||||
|
12
backend/API/Models/RecipeModels/GetAllRecipesDTO.cs
Normal file
12
backend/API/Models/RecipeModels/GetAllRecipesDTO.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace API.Models.RecipeModels
|
||||
{
|
||||
public class GetAllRecipesDTO
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user