geethareddy commited on
Commit
e4d69fd
·
verified ·
1 Parent(s): 0b09da2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -35,8 +35,8 @@ sf = get_salesforce_connection()
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,30 +47,30 @@ def get_menu_items():
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)
 
35
  def index():
36
  return render_template('index.html')
37
 
38
+ @app.route('/get_ingredients', methods=['POST'])
39
+ def get_ingredients():
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': "Category__c = 'Veg'",
51
+ 'non-vegetarian': "Category__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
58
+ soql = "SELECT Name, Image_URL__c FROM Sector_Detail__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
+ ingredients = [
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(ingredients)} ingredients: {ingredients}")
70
+ return jsonify({"ingredients": ingredients})
71
  except Exception as e:
72
+ logger.error(f"Failed to fetch ingredients: {str(e)}")
73
+ return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
74
 
75
  if __name__ == '__main__':
76
  app.run(debug=True, host='0.0.0.0', port=7860)