From 95e41b813fa45e3a224a7d766291bce52e75abbc Mon Sep 17 00:00:00 2001 From: Stepan Date: Sun, 29 Jun 2025 15:02:57 +0200 Subject: [PATCH] Added ajax endpoints to search and create ingredient --- apps/Ajax/ajax-actions.php | 50 +++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/apps/Ajax/ajax-actions.php b/apps/Ajax/ajax-actions.php index 1e3f1aa..15945d5 100644 --- a/apps/Ajax/ajax-actions.php +++ b/apps/Ajax/ajax-actions.php @@ -1,6 +1,7 @@ field_name = $ingredient_name; + $ingredient->field_unit_name = $ingredient_unit; + $ingredient->save(); + + $result = array(); + $result['success'] = 'You have successfully added new ingredient'; + return $result; +} +function ajax_search_ingredient() +{ + $search_query = $_POST['query'] ?? null; + if (!isset($search_query)) { + return get_ajax_error("Missing 'query' parameter.", 400); + } + $result = array(); + + $ingredients = IngredientModel::filter( + count: 5, + search: $search_query + ); + $result['count'] = count($ingredients); + $result['result'] = $ingredients; + + return $result; +} \ No newline at end of file -- 2.34.1