buildRoutesWithReflection static method

Future<Router?> buildRoutesWithReflection(
  1. Object controller
)

Build router from controller annotations (Spring Boot style)

Implementation

static Future<Router?> buildRoutesWithReflection(Object controller) async {
  if (!isReflectionAvailable) {
    Log.w('Reflection not available. Use manual route registration.');
    return null;
  }

  try {
    Log.i('Building routes from annotations...');
    final router = Router();
    final routes = _extractRoutes(controller);

    // Sort by specificity (static routes first)
    routes.sort((a, b) => a.specificity.compareTo(b.specificity));

    // Register routes in router with JWT middleware
    for (final route in routes) {
      await _registerRoute(router, route);
    }

    Log.i('Successfully registered ${routes.length} routes');
    return router;
  } catch (e, stackTrace) {
    Log.e('Error building routes with reflection', error: e, stackTrace: stackTrace);
    return null;
  }
}