Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,8 +82,8 @@ def get_ingredients():
|
|
| 82 |
return jsonify({"error": f"Failed to fetch ingredients from Salesforce: {str(e)}"}), 500
|
| 83 |
|
| 84 |
|
| 85 |
-
@app.route('/
|
| 86 |
-
def
|
| 87 |
global sf
|
| 88 |
if not sf:
|
| 89 |
sf = get_salesforce_connection()
|
|
@@ -95,25 +95,33 @@ def get_menu_items():
|
|
| 95 |
category = data.get('category', '')
|
| 96 |
|
| 97 |
try:
|
| 98 |
-
|
|
|
|
| 99 |
conditions = []
|
|
|
|
| 100 |
if ingredient_names:
|
| 101 |
words = ingredient_names.split()
|
| 102 |
-
name_conditions = [f"
|
| 103 |
conditions.append(f"({' OR '.join(name_conditions)})")
|
|
|
|
| 104 |
if category:
|
| 105 |
if category.lower() == 'vegetarian':
|
| 106 |
conditions.append("Veg_NonVeg__c = 'Vegetarian'")
|
| 107 |
elif category.lower() == 'non-vegetarian':
|
| 108 |
conditions.append("Veg_NonVeg__c = 'Non-Vegetarian'")
|
|
|
|
| 109 |
if conditions:
|
| 110 |
soql += " WHERE " + " AND ".join(conditions)
|
|
|
|
| 111 |
soql += " LIMIT 200"
|
| 112 |
-
logger.debug(f"Executing SOQL query for
|
|
|
|
| 113 |
result = sf.query(soql)
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
{
|
| 116 |
-
"name": record['
|
| 117 |
"description": record.get('Description__c', 'No description available'),
|
| 118 |
"image_url": record.get('Image1__c', '') or record.get('Image2__c', ''),
|
| 119 |
"price": record.get('Price__c', 0.0),
|
|
@@ -121,13 +129,15 @@ def get_menu_items():
|
|
| 121 |
"veg_nonveg": record.get('Veg_NonVeg__c', ''),
|
| 122 |
"total_ordered": record.get('Total_Ordered__c', 0)
|
| 123 |
}
|
| 124 |
-
for record in result['records'] if '
|
| 125 |
]
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
except Exception as e:
|
| 129 |
-
logger.error(f"Failed to fetch
|
| 130 |
-
return jsonify({"error": f"Failed to fetch
|
| 131 |
|
| 132 |
@app.route('/submit_customization_ingredients', methods=['POST'])
|
| 133 |
def submit_customization_ingredients():
|
|
|
|
| 82 |
return jsonify({"error": f"Failed to fetch ingredients from Salesforce: {str(e)}"}), 500
|
| 83 |
|
| 84 |
|
| 85 |
+
@app.route('/get_recipe_items', methods=['POST'])
|
| 86 |
+
def get_recipe_items():
|
| 87 |
global sf
|
| 88 |
if not sf:
|
| 89 |
sf = get_salesforce_connection()
|
|
|
|
| 95 |
category = data.get('category', '')
|
| 96 |
|
| 97 |
try:
|
| 98 |
+
# Modify the SOQL to fetch data from Recipe_Object__c object
|
| 99 |
+
soql = "SELECT Recipe_Name__c, Description__c, Image1__c, Image2__c, Price__c, Section__c, Veg_NonVeg__c, Total_Ordered__c FROM Recipe_Object__c"
|
| 100 |
conditions = []
|
| 101 |
+
|
| 102 |
if ingredient_names:
|
| 103 |
words = ingredient_names.split()
|
| 104 |
+
name_conditions = [f"Recipe_Name__c LIKE '%{word}%'" for word in words]
|
| 105 |
conditions.append(f"({' OR '.join(name_conditions)})")
|
| 106 |
+
|
| 107 |
if category:
|
| 108 |
if category.lower() == 'vegetarian':
|
| 109 |
conditions.append("Veg_NonVeg__c = 'Vegetarian'")
|
| 110 |
elif category.lower() == 'non-vegetarian':
|
| 111 |
conditions.append("Veg_NonVeg__c = 'Non-Vegetarian'")
|
| 112 |
+
|
| 113 |
if conditions:
|
| 114 |
soql += " WHERE " + " AND ".join(conditions)
|
| 115 |
+
|
| 116 |
soql += " LIMIT 200"
|
| 117 |
+
logger.debug(f"Executing SOQL query for Recipe_Object__c: {soql}")
|
| 118 |
+
|
| 119 |
result = sf.query(soql)
|
| 120 |
+
|
| 121 |
+
# Map the result to the response
|
| 122 |
+
recipe_items = [
|
| 123 |
{
|
| 124 |
+
"name": record['Recipe_Name__c'],
|
| 125 |
"description": record.get('Description__c', 'No description available'),
|
| 126 |
"image_url": record.get('Image1__c', '') or record.get('Image2__c', ''),
|
| 127 |
"price": record.get('Price__c', 0.0),
|
|
|
|
| 129 |
"veg_nonveg": record.get('Veg_NonVeg__c', ''),
|
| 130 |
"total_ordered": record.get('Total_Ordered__c', 0)
|
| 131 |
}
|
| 132 |
+
for record in result['records'] if 'Recipe_Name__c' in record
|
| 133 |
]
|
| 134 |
+
|
| 135 |
+
logger.debug(f"Fetched {len(recipe_items)} recipe items")
|
| 136 |
+
return jsonify({"recipe_items": recipe_items})
|
| 137 |
+
|
| 138 |
except Exception as e:
|
| 139 |
+
logger.error(f"Failed to fetch recipe items: {str(e)}")
|
| 140 |
+
return jsonify({"error": f"Failed to fetch recipe items from Salesforce: {str(e)}"}), 500
|
| 141 |
|
| 142 |
@app.route('/submit_customization_ingredients', methods=['POST'])
|
| 143 |
def submit_customization_ingredients():
|