From 71d499aee122ab44110ad0e876e49c4585b4d28e Mon Sep 17 00:00:00 2001 From: oguz ozturk Date: Mon, 12 Jan 2026 18:21:18 +0300 Subject: [PATCH] feat: Add endpoint to fetch available Cloudflare accounts for customers --- backend/app/routes/customer.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/backend/app/routes/customer.py b/backend/app/routes/customer.py index dde86de..780a231 100644 --- a/backend/app/routes/customer.py +++ b/backend/app/routes/customer.py @@ -12,6 +12,48 @@ from datetime import datetime customer_bp = Blueprint('customer', __name__, url_prefix='/api/customer') +@customer_bp.route('/cloudflare-accounts', methods=['GET']) +@token_required +def get_cloudflare_accounts(current_user): + """Get available Cloudflare accounts for customer""" + try: + customer = current_user.customer + if not customer: + return jsonify({'error': 'Customer profile not found'}), 404 + + # Fetch available CF accounts from Admin Panel + admin_api = AdminAPIService() + accounts_result = admin_api.get_available_cf_accounts() + + if accounts_result['status'] == 'success': + # Filter only active accounts with available capacity + available_accounts = [ + acc for acc in accounts_result.get('accounts', []) + if acc.get('is_active') and acc.get('available_capacity', 0) > 0 + ] + + return jsonify({ + 'status': 'success', + 'accounts': available_accounts, + 'total': len(available_accounts) + }), 200 + else: + return jsonify({ + 'status': 'error', + 'accounts': [], + 'total': 0, + 'error': accounts_result.get('error', 'Failed to fetch CF accounts') + }), 200 + + except Exception as e: + return jsonify({ + 'status': 'error', + 'accounts': [], + 'total': 0, + 'error': str(e) + }), 500 + + @customer_bp.route('/domains', methods=['GET']) @token_required def get_domains(current_user):