rairo commited on
Commit
d1a4128
·
verified ·
1 Parent(s): 5e9aee0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +43 -0
main.py CHANGED
@@ -484,6 +484,8 @@ def admin_action_on_role(application_id):
484
  except firebase_exceptions.FirebaseError as fe: logger.error(f"Firebase error in admin_action_on_role: {fe}"); return jsonify({'error': f'Firebase error: {str(fe)}'}), 500
485
  except Exception as e: logger.error(f"Admin Role Action Error: {e}"); return jsonify({'error': f'Failed to process: {str(e)}'}), 500
486
 
 
 
487
  # --- Marketplace Endpoints ---
488
  def _create_listing(uid_lister, listing_type, data):
489
  if not FIREBASE_INITIALIZED: raise ConnectionError("Firebase not ready for listing creation.")
@@ -921,6 +923,47 @@ def admin_respond_to_transporter_counter(deal_id):
921
  except Exception as e:
922
  return handle_route_errors(e, uid_context=reviewer_uid)
923
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
924
 
925
  # --- NEW: /api/deals/my Endpoint ---
926
  @app.route('/api/deals/my', methods=['GET'])
 
484
  except firebase_exceptions.FirebaseError as fe: logger.error(f"Firebase error in admin_action_on_role: {fe}"); return jsonify({'error': f'Firebase error: {str(fe)}'}), 500
485
  except Exception as e: logger.error(f"Admin Role Action Error: {e}"); return jsonify({'error': f'Failed to process: {str(e)}'}), 500
486
 
487
+
488
+
489
  # --- Marketplace Endpoints ---
490
  def _create_listing(uid_lister, listing_type, data):
491
  if not FIREBASE_INITIALIZED: raise ConnectionError("Firebase not ready for listing creation.")
 
923
  except Exception as e:
924
  return handle_route_errors(e, uid_context=reviewer_uid)
925
 
926
+ # --- NEW: Admin Endpoint to Get All Listings ---
927
+ @app.route('/api/admin/listings/all', methods=['GET'])
928
+ def admin_get_all_listings():
929
+ auth_header = request.headers.get('Authorization')
930
+ admin_uid = None
931
+ try:
932
+ admin_uid = verify_admin(auth_header) # Ensures only an admin can access
933
+ if not FIREBASE_INITIALIZED:
934
+ return jsonify({'error': 'Server configuration error: Firebase not ready.'}), 503
935
+
936
+ listings_ref = db.reference('listings', app=db_app)
937
+ all_listings = listings_ref.get() or {} # Get all listings, or empty dict if node doesn't exist
938
+
939
+ # You might want to add pagination here if the number of listings can be very large
940
+ # For now, it returns all listings.
941
+
942
+ return jsonify(all_listings), 200
943
+
944
+ except Exception as e: # Catches errors from verify_admin and DB operations
945
+ return handle_route_errors(e, uid_context=admin_uid)
946
+
947
+
948
+ # --- NEW: Admin Endpoint to Get All Deals ---
949
+ @app.route('/api/admin/deals/all', methods=['GET'])
950
+ def admin_get_all_deals():
951
+ auth_header = request.headers.get('Authorization')
952
+ admin_uid = None
953
+ try:
954
+ admin_uid = verify_admin(auth_header) # Ensures only an admin can access
955
+ if not FIREBASE_INITIALIZED:
956
+ return jsonify({'error': 'Server configuration error: Firebase not ready.'}), 503
957
+
958
+ deals_ref = db.reference('deals', app=db_app)
959
+ all_deals = deals_ref.get() or {} # Get all deals, or empty dict if node doesn't exist
960
+
961
+ # Similar to listings, consider pagination for very large numbers of deals.
962
+
963
+ return jsonify(all_deals), 200
964
+
965
+ except Exception as e: # Catches errors from verify_admin and DB operations
966
+ return handle_route_errors(e, uid_context=admin_uid)
967
 
968
  # --- NEW: /api/deals/my Endpoint ---
969
  @app.route('/api/deals/my', methods=['GET'])