# Script to fix decorator placement in admin_routes.py

file_path = r'd:\bookbeach\backend\app\routes\admin_routes.py'

# Read the file
with open(file_path, 'r', encoding='utf-8') as f:
    lines = f.readlines()

# Find and fix the decorator placement issue
fixed_lines = []
i = 0
while i < len(lines):
    # Check if we have the problematic pattern: multiple blank lines followed by a decorator
    if (i + 3 < len(lines) and 
        lines[i].strip() == '' and 
        lines[i + 1].strip() == '' and
        lines[i + 2].strip() == '' and
        lines[i + 3].strip().startswith('@admin_bp.route')):
        # Skip the extra blank lines
        print(f"Found extra blank lines before decorator at line {i}")
        # Add just one blank line before the decorator
        fixed_lines.append('\n')
        fixed_lines.append(lines[i + 3])  # Add the decorator
        i += 4  # Skip the processed lines
    else:
        fixed_lines.append(lines[i])
        i += 1

# Write the fixed content back
with open(file_path, 'w', encoding='utf-8') as f:
    f.writelines(fixed_lines)

print("Fixed decorator placement in admin_routes.py")