routeGetAll method

WebRoute routeGetAll(
  1. String path, {
  2. required WebRequest rq,
  3. List<String> methods = const [RequestMethods.GET],
  4. Future<ApiDoc>? apiDoc()?,
  5. WaAuthController? auth,
  6. List<String> extraPath = const [],
  7. List<String> excludePaths = const [],
  8. List<String> hosts = const ['*'],
  9. Map<String, Object?> params = const {},
  10. List<String> permissions = const [],
  11. List<int> ports = const [],
  12. List<WebRoute> children = const [],
  13. bool paging = true,
  14. int pageSize = 20,
  15. bool orderReverse = true,
  16. 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
  • rq - Web request instance
  • 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 WebRoute configured for listing documents.

Example response:

{
  "success": true,
  "data": [...],
  "paging": {
    "page": 1,
    "pageSize": 20,
    "total": 100,
    "totalPages": 5
  }
}

Implementation

WebRoute routeGetAll(String path,
    {required WebRequest rq,
    List<String> methods = const [RequestMethods.GET],
    Future<ApiDoc>? Function()? apiDoc,
    WaAuthController? 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<WebRoute> children = const [],
    bool paging = true,
    int pageSize = 20,
    bool orderReverse = true,
    String orderBy = '_id'}) {
  Future<String> index() async {
    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(
        rq: rq,
        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 WebRoute(
    path: path,
    methods: methods,
    rq: rq,
    apiDoc: apiDoc,
    auth: auth,
    excludePaths: excludePaths,
    extraPath: extraPath,
    hosts: hosts,
    params: params,
    permissions: permissions,
    ports: ports,
    index: index,
    children: children,
  );
}