Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,6 +61,33 @@ def get_ingredients():
|
|
| 61 |
except Exception as e:
|
| 62 |
logging.error(f"Error while fetching ingredients: {str(e)}")
|
| 63 |
return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
@app.route('/get_menu_items', methods=['POST'])
|
| 66 |
def get_menu_items():
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
logging.error(f"Error while fetching ingredients: {str(e)}")
|
| 63 |
return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
|
| 64 |
+
@app.route('/get_menu_items', methods=['POST'])
|
| 65 |
+
def get_menu_items():
|
| 66 |
+
category = request.json.get('category', '').strip().lower()
|
| 67 |
+
logging.debug(f"Received category: {category}")
|
| 68 |
+
|
| 69 |
+
soql = ""
|
| 70 |
+
if category == 'chicken':
|
| 71 |
+
soql = "SELECT Item_Name__c, Image_URL__c FROM Menu_Item__c WHERE Category__c = 'Chicken' LIMIT 200"
|
| 72 |
+
elif category == 'mutton':
|
| 73 |
+
soql = "SELECT Item_Name__c, Image_URL__c FROM Menu_Item__c WHERE Category__c = 'Mutton' LIMIT 200"
|
| 74 |
+
elif category == 'non-vegetarian':
|
| 75 |
+
soql = "SELECT Item_Name__c, Image_URL__c FROM Menu_Item__c WHERE Category__c IN ('Chicken', 'Mutton', 'Fish') LIMIT 200"
|
| 76 |
+
else:
|
| 77 |
+
logging.debug("Invalid category received.")
|
| 78 |
+
return jsonify({"error": "Invalid category."}), 400
|
| 79 |
+
|
| 80 |
+
try:
|
| 81 |
+
result = sf.query(soql)
|
| 82 |
+
menu_items = [
|
| 83 |
+
{"name": record['Item_Name__c'], "image_url": record.get('Image_URL__c', '')}
|
| 84 |
+
for record in result['records'] if 'Item_Name__c' in record
|
| 85 |
+
]
|
| 86 |
+
logging.debug(f"Fetched {len(menu_items)} menu items.")
|
| 87 |
+
return jsonify({"menu_items": menu_items})
|
| 88 |
+
except Exception as e:
|
| 89 |
+
logging.error(f"Error while fetching menu items: {str(e)}")
|
| 90 |
+
return jsonify({"error": f"Failed to fetch menu items: {str(e)}"}), 500
|
| 91 |
|
| 92 |
@app.route('/get_menu_items', methods=['POST'])
|
| 93 |
def get_menu_items():
|