Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,8 +35,8 @@ sf = get_salesforce_connection()
|
|
| 35 |
def index():
|
| 36 |
return render_template('index.html')
|
| 37 |
|
| 38 |
-
@app.route('/
|
| 39 |
-
def
|
| 40 |
global sf
|
| 41 |
if not sf:
|
| 42 |
sf = get_salesforce_connection()
|
|
@@ -47,30 +47,30 @@ def get_ingredients():
|
|
| 47 |
|
| 48 |
# Map dietary preference to SOQL condition
|
| 49 |
preference_map = {
|
| 50 |
-
'vegetarian': "
|
| 51 |
-
'non-vegetarian': "
|
| 52 |
'both': None # No condition to fetch all records
|
| 53 |
}
|
| 54 |
condition = preference_map.get(dietary_preference)
|
| 55 |
|
| 56 |
try:
|
| 57 |
-
# Construct the base query
|
| 58 |
-
soql = "SELECT Name, Image_URL__c FROM
|
| 59 |
if condition:
|
| 60 |
soql += f" WHERE {condition}"
|
| 61 |
soql += " LIMIT 200"
|
| 62 |
|
| 63 |
logger.info(f"Executing SOQL query: {soql}")
|
| 64 |
result = sf.query(soql)
|
| 65 |
-
|
| 66 |
{"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
|
| 67 |
for record in result['records'] if 'Name' in record
|
| 68 |
]
|
| 69 |
-
logger.info(f"Fetched {len(
|
| 70 |
-
return jsonify({"
|
| 71 |
except Exception as e:
|
| 72 |
-
logger.error(f"Failed to fetch
|
| 73 |
-
return jsonify({"error": f"Failed to fetch
|
| 74 |
|
| 75 |
if __name__ == '__main__':
|
| 76 |
app.run(debug=True, host='0.0.0.0', port=7860)
|
|
|
|
| 35 |
def index():
|
| 36 |
return render_template('index.html')
|
| 37 |
|
| 38 |
+
@app.route('/get_menu_items', methods=['POST'])
|
| 39 |
+
def get_menu_items():
|
| 40 |
global sf
|
| 41 |
if not sf:
|
| 42 |
sf = get_salesforce_connection()
|
|
|
|
| 47 |
|
| 48 |
# Map dietary preference to SOQL condition
|
| 49 |
preference_map = {
|
| 50 |
+
'vegetarian': "Sector__c = 'Veg'",
|
| 51 |
+
'non-vegetarian': "Sector__c = 'Non-Veg'",
|
| 52 |
'both': None # No condition to fetch all records
|
| 53 |
}
|
| 54 |
condition = preference_map.get(dietary_preference)
|
| 55 |
|
| 56 |
try:
|
| 57 |
+
# Construct the base query for Menu_Item__c
|
| 58 |
+
soql = "SELECT Name, Image_URL__c FROM Menu_Item__c"
|
| 59 |
if condition:
|
| 60 |
soql += f" WHERE {condition}"
|
| 61 |
soql += " LIMIT 200"
|
| 62 |
|
| 63 |
logger.info(f"Executing SOQL query: {soql}")
|
| 64 |
result = sf.query(soql)
|
| 65 |
+
menu_items = [
|
| 66 |
{"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
|
| 67 |
for record in result['records'] if 'Name' in record
|
| 68 |
]
|
| 69 |
+
logger.info(f"Fetched {len(menu_items)} menu items: {menu_items}")
|
| 70 |
+
return jsonify({"menu_items": menu_items})
|
| 71 |
except Exception as e:
|
| 72 |
+
logger.error(f"Failed to fetch menu items: {str(e)}")
|
| 73 |
+
return jsonify({"error": f"Failed to fetch menu items: {str(e)}"}), 500
|
| 74 |
|
| 75 |
if __name__ == '__main__':
|
| 76 |
app.run(debug=True, host='0.0.0.0', port=7860)
|