Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -51,13 +51,10 @@ def get_menu_items(): | |
| 51 |  | 
| 52 | 
             
                try:
         | 
| 53 | 
             
                    soql = "SELECT Name, Image_URL__c, Category__c, Description__c FROM Sector_Detail__c"
         | 
| 54 | 
            -
                    conditions = []
         | 
| 55 | 
             
                    if search_term:
         | 
| 56 | 
            -
                         | 
| 57 | 
             
                    if dietary_preference in ['vegetarian', 'non-vegetarian']:
         | 
| 58 | 
            -
                         | 
| 59 | 
            -
                    if conditions:
         | 
| 60 | 
            -
                        soql += " WHERE " + " AND ".join(conditions)
         | 
| 61 | 
             
                    soql += " LIMIT 200"
         | 
| 62 |  | 
| 63 | 
             
                    logger.info(f"Executing SOQL query: {soql}")
         | 
| @@ -74,7 +71,7 @@ def get_menu_items(): | |
| 74 | 
             
                    logger.info(f"Fetched {len(items)} items from Sector_Detail__c for {dietary_preference} with search '{search_term}'")
         | 
| 75 | 
             
                    return jsonify({"menu_items": items})
         | 
| 76 | 
             
                except Exception as e:
         | 
| 77 | 
            -
                    logger.error(f"Failed to fetch items from Sector_Detail__c: {e}")
         | 
| 78 | 
             
                    return jsonify({"error": f"Failed to fetch items from Salesforce: {str(e)}"}), 500
         | 
| 79 |  | 
| 80 | 
             
            # Fetch suggestions from Ingredient_Object__c
         | 
| @@ -197,7 +194,7 @@ def get_sector_item_details(): | |
| 197 | 
             
                        "category": record.get('Category__c', 'Unknown'),
         | 
| 198 | 
             
                        "description": record.get('Description__c', 'No description available')
         | 
| 199 | 
             
                    }
         | 
| 200 | 
            -
                    logger.info(f"Fetched details for '{item_name}' from Sector_Detail__c | 
| 201 | 
             
                    return jsonify({"item_details": item_details})
         | 
| 202 | 
             
                except Exception as e:
         | 
| 203 | 
             
                    logger.error(f"Failed to fetch item details from Sector_Detail__c: {str(e)}")
         | 
| @@ -218,10 +215,10 @@ def submit_items(): | |
| 218 |  | 
| 219 | 
             
                try:
         | 
| 220 | 
             
                    for item in items:
         | 
| 221 | 
            -
                        logger.info(f"Submitting item | 
| 222 | 
             
                        sf.Ingredient_Object__c.create({
         | 
| 223 | 
             
                            'Ingredient_Name__c': item['name'],
         | 
| 224 | 
            -
                            'Category__c': item.get('category', 'Unknown'), | 
| 225 | 
             
                            'Description__c': item.get('description', 'No description available')
         | 
| 226 | 
             
                        })
         | 
| 227 | 
             
                        logger.info(f"Successfully submitted item to Ingredient_Object__c: {item['name']}")
         | 
|  | |
| 51 |  | 
| 52 | 
             
                try:
         | 
| 53 | 
             
                    soql = "SELECT Name, Image_URL__c, Category__c, Description__c FROM Sector_Detail__c"
         | 
|  | |
| 54 | 
             
                    if search_term:
         | 
| 55 | 
            +
                        soql += f" WHERE Name LIKE '%{search_term}%'"
         | 
| 56 | 
             
                    if dietary_preference in ['vegetarian', 'non-vegetarian']:
         | 
| 57 | 
            +
                        soql += f"{' AND' if search_term else ' WHERE'} Category__c = '{dietary_preference.capitalize()}'"
         | 
|  | |
|  | |
| 58 | 
             
                    soql += " LIMIT 200"
         | 
| 59 |  | 
| 60 | 
             
                    logger.info(f"Executing SOQL query: {soql}")
         | 
|  | |
| 71 | 
             
                    logger.info(f"Fetched {len(items)} items from Sector_Detail__c for {dietary_preference} with search '{search_term}'")
         | 
| 72 | 
             
                    return jsonify({"menu_items": items})
         | 
| 73 | 
             
                except Exception as e:
         | 
| 74 | 
            +
                    logger.error(f"Failed to fetch items from Sector_Detail__c: {str(e)}")
         | 
| 75 | 
             
                    return jsonify({"error": f"Failed to fetch items from Salesforce: {str(e)}"}), 500
         | 
| 76 |  | 
| 77 | 
             
            # Fetch suggestions from Ingredient_Object__c
         | 
|  | |
| 194 | 
             
                        "category": record.get('Category__c', 'Unknown'),
         | 
| 195 | 
             
                        "description": record.get('Description__c', 'No description available')
         | 
| 196 | 
             
                    }
         | 
| 197 | 
            +
                    logger.info(f"Fetched details for '{item_name}' from Sector_Detail__c")
         | 
| 198 | 
             
                    return jsonify({"item_details": item_details})
         | 
| 199 | 
             
                except Exception as e:
         | 
| 200 | 
             
                    logger.error(f"Failed to fetch item details from Sector_Detail__c: {str(e)}")
         | 
|  | |
| 215 |  | 
| 216 | 
             
                try:
         | 
| 217 | 
             
                    for item in items:
         | 
| 218 | 
            +
                        logger.info(f"Submitting item: {item}")
         | 
| 219 | 
             
                        sf.Ingredient_Object__c.create({
         | 
| 220 | 
             
                            'Ingredient_Name__c': item['name'],
         | 
| 221 | 
            +
                            'Category__c': item.get('category', 'Unknown'),
         | 
| 222 | 
             
                            'Description__c': item.get('description', 'No description available')
         | 
| 223 | 
             
                        })
         | 
| 224 | 
             
                        logger.info(f"Successfully submitted item to Ingredient_Object__c: {item['name']}")
         | 
