routeGetAll method

FinchRoute routeGetAll(
  1. String path, {
  2. List<String> methods = const [Methods.GET],
  3. Future<ApiDoc>? apiDoc()?,
  4. AuthController? auth,
  5. List<String> extraPath = const [],
  6. List<String> excludePaths = const [],
  7. List<String> hosts = const ['*'],
  8. Map<String, Object?> params = const {},
  9. List<String> permissions = const [],
  10. List<int> ports = const [],
  11. List<FinchRoute> children = const [],
  12. bool paging = true,
  13. int pageSize = 20,
  14. bool orderReverse = true,
  15. String orderBy = '_id',
})

Creates a route for retrieving all documents in the collection. This method generates a REST API endpoint that handles listing all documents in the collection with support for:

  • Search functionality across searchable fields
  • Filtering by filterable fields
  • Pagination with customizable page sizes
  • Sorting by any field The route automatically handles query parameters for pagination, search terms, and filters based on the form field definitions. Parameters:
  • path - URL path for this route
  • methods - HTTP methods to accept (default: GET)
  • apiDoc - Optional API documentation generator
  • auth - Optional authentication controller
  • extraPath - Additional path segments to match
  • excludePaths - Path segments to exclude from matching
  • hosts - Host names to match (default: all hosts)
  • params - Additional route parameters
  • permissions - Required permissions for access
  • ports - Specific ports to match
  • children - Child routes
  • paging - Enable pagination
  • pageSize - Default page size
  • orderReverse - Default sort order
  • orderBy - Default sort field Returns a FinchRoute configured for listing documents. Example response:
{
  "success": true,
  "data": [...],
  "paging": {
    "page": 1,
    "pageSize": 20,
    "total": 100,
    "totalPages": 5
  }
}

Implementation

FinchRoute routeGetAll(String path,
    {List<String> methods = const [Methods.GET],
    Future<ApiDoc>? Function()? apiDoc,
    AuthController? auth,
    List<String> extraPath = const [],
    List<String> excludePaths = const [],
    List<String> hosts = const ['*'],
    Map<String, Object?> params = const {},
    List<String> permissions = const [],
    List<int> ports = const [],
    List<FinchRoute> children = const [],
    bool paging = true,
    int pageSize = 20,
    bool orderReverse = true,
    String orderBy = '_id'}) {
  Future<String> index() async {
    final rq = Context.rq;
    if (paging == false) {
      var all = await getAll(
        filter: getSearchableFilter(inputs: rq.getAll()),
      );

      return rq.renderData(data: {
        'success': true,
        'data': all,
      });
    } else {
      final countAll = await getCount(
        filter: getSearchableFilter(inputs: rq.getAll()),
      );
      pageSize = rq.get<int>('pageSize', def: pageSize);
      orderBy = rq.get<String>('orderBy', def: orderBy);
      orderReverse = rq.get<bool>('orderReverse', def: orderReverse);

      UIPaging paging = UIPaging(
        total: countAll,
        pageSize: pageSize,
        widget: '',
        page: rq.get<int>('page', def: 1),
        orderReverse: orderReverse,
        orderBy: orderBy,
      );

      final res = await getAll(
        filter: getSearchableFilter(inputs: rq.getAll()),
        limit: paging.pageSize,
        skip: paging.start,
        sort: DQ.order(orderBy, orderReverse),
      );

      return rq.renderData(data: {
        'success': true,
        'data': res,
        'paging': await paging.renderData(),
      });
    }
  }

  return FinchRoute(
    path: path,
    methods: methods,
    apiDoc: apiDoc,
    auth: auth,
    excludePaths: excludePaths,
    extraPath: extraPath,
    hosts: hosts,
    params: params,
    permissions: permissions,
    ports: ports,
    index: index,
    children: children,
  );
}