feat: Add endpoint to fetch available Cloudflare accounts for customers

This commit is contained in:
oguz ozturk 2026-01-12 18:21:18 +03:00
parent 2d3318647a
commit 71d499aee1
1 changed files with 42 additions and 0 deletions

View File

@ -12,6 +12,48 @@ from datetime import datetime
customer_bp = Blueprint('customer', __name__, url_prefix='/api/customer') 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']) @customer_bp.route('/domains', methods=['GET'])
@token_required @token_required
def get_domains(current_user): def get_domains(current_user):