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',
})

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'}) {
  final index = () async {
    if (paging == false) {
      var all = await getAll(
        filter: getSearchableFilter(inputs: rq.getAllData()),
      );

      return rq.renderData(data: {
        'success': true,
        'data': all,
      });
    } else {
      final countAll = await getCount(
        filter: getSearchableFilter(inputs: rq.getAllData()),
      );
      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.getAllData()),
        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,
  );
}