rairo commited on
Commit
2dd9b40
·
verified ·
1 Parent(s): fa37fed

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -1
main.py CHANGED
@@ -190,6 +190,36 @@ def handle_route_errors(e, uid_context="unknown"): # Added uid_context for bette
190
  logger.error(f"Unexpected Error in route (UID context: {uid_context}): {e}\n{traceback.format_exc()}")
191
  return jsonify({'error': f'An unexpected error occurred: {str(e)}', 'type': 'GenericError'}), 500
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  # --- Authentication Endpoints ---
194
  @app.route('/api/auth/signup', methods=['POST'])
195
  def signup():
@@ -526,7 +556,6 @@ def admin_action_on_listing(listing_id):
526
  except Exception as e: return handle_route_errors(e, uid_context=reviewer_uid)
527
 
528
  # --- Deal Management (MODIFIED SECTION) ---
529
- # --- (This endpoint replaces your existing /api/deals/propose) ---
530
  @app.route('/api/deals/propose', methods=['POST'])
531
  def propose_deal():
532
  auth_header = request.headers.get('Authorization')
 
190
  logger.error(f"Unexpected Error in route (UID context: {uid_context}): {e}\n{traceback.format_exc()}")
191
  return jsonify({'error': f'An unexpected error occurred: {str(e)}', 'type': 'GenericError'}), 500
192
 
193
+
194
+ # --- system notifications ---
195
+
196
+ def _send_system_notification(user_id, message_content, notif_type, link=None): # Renamed message to message_content
197
+ if not FIREBASE_INITIALIZED:
198
+ logger.error("_send_system_notification: Firebase not ready.")
199
+ return False
200
+ if not user_id or not message_content:
201
+ logger.warning(f"_send_system_notification: Called with missing user_id ('{user_id}') or message_content ('{message_content}').")
202
+ return False
203
+
204
+ notif_id = str(uuid.uuid4())
205
+ notif_data = {
206
+ "message": message_content,
207
+ "type": notif_type,
208
+ "link": link,
209
+ "created_at": datetime.now(timezone.utc).isoformat(),
210
+ "read": False
211
+ }
212
+ try:
213
+ db.reference(f'notifications/{user_id}/{notif_id}', app=db_app).set(notif_data)
214
+ logger.info(f"Notification sent to {user_id}: {message_content[:50]}...")
215
+ return True
216
+ except firebase_exceptions.FirebaseError as fe:
217
+ logger.error(f"Failed to send notification to {user_id} due to Firebase error: {fe}")
218
+ return False
219
+ except Exception as e:
220
+ logger.error(f"Failed to send notification to {user_id} due to generic error: {e}")
221
+ return False
222
+
223
  # --- Authentication Endpoints ---
224
  @app.route('/api/auth/signup', methods=['POST'])
225
  def signup():
 
556
  except Exception as e: return handle_route_errors(e, uid_context=reviewer_uid)
557
 
558
  # --- Deal Management (MODIFIED SECTION) ---
 
559
  @app.route('/api/deals/propose', methods=['POST'])
560
  def propose_deal():
561
  auth_header = request.headers.get('Authorization')