routeDeleteOne method
WebRoute
routeDeleteOne(
- 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 [],
Creates a route for deleting documents from the collection.
This method generates a REST API endpoint that handles document deletion by ID. The route expects a document ID in the URL path and processes GET requests to delete the specified document.
The delete operation:
- Validates the document ID format
- Checks if the document exists
- Triggers the onDelete event if successful
Parameters:
path
- URL path for this route (should include {id} placeholder)rq
- 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 match
Returns a WebRoute configured for deleting documents.
Success response (200):
{
"success": true,
"message": "deleted"
}
Error responses:
- 404: Document not found
- 502: Missing or invalid ID
Implementation
WebRoute routeDeleteOne(
String path, {
required WebRequest rq,
List<String> methods = const [RequestMethods.GET],
Future<ApiDoc>? Function()? apiDoc,
WaAuthController<dynamic>? 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 [],
}) {
Future<String> index() async {
var id = rq.getParam('id', def: '').toString();
if (id.isEmpty) {
return rq.renderData(
data: {
'success': false,
'message': 'id is required',
},
status: 502,
);
}
var data = await delete(id);
if (!data) {
return rq.renderData(
data: {
'success': false,
'message': 'id not found',
},
status: 404,
);
}
return rq.renderData(data: {
'success': true,
'message': 'deleted',
});
}
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,
);
}