routeGetAll method
WebRoute
routeGetAll(
- String path, {
- required WebRequest rq,
- List<
String> methods = const [RequestMethods.GET], - Future<
ApiDoc> ? 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',
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 routerq
- Web request instancemethods
- HTTP methods to accept (default: GET)apiDoc
- Optional API documentation generatorauth
- Optional authentication controllerextraPath
- Additional path segments to matchexcludePaths
- Path segments to exclude from matchinghosts
- Host names to match (default: all hosts)params
- Additional route parameterspermissions
- Required permissions for accessports
- Specific ports to matchchildren
- Child routespaging
- Enable paginationpageSize
- Default page sizeorderReverse
- Default sort orderorderBy
- 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,
);
}