rename method
Renames the document referred to by this DocumentReference.
Implementation
@Deprecated('Documents cannot be renamed in CAWS.')
Future<DocumentSnapshot> rename(String name) async {
assert(name.isNotEmpty, 'Document path names cannot be empty.');
assert(RegExp(r'^[a-zA-Z0-9_-]+$').hasMatch(name),
'Document name can only contain alphanumeric, hyphen (-), and underscore (_) characters.');
// if we don't have the document ID, get it first.
if (id == null) _id = (await get())?.id;
if (_id == null) {
// early out if this document does not exist
throw CarpServiceException(message: 'No valid document id found.');
}
Map<String, dynamic> payload = {'name': name};
final response = await service._put(
Uri.encodeFull(documentUri),
body: json.encode(payload),
);
int httpStatusCode = response.statusCode;
Map<String, dynamic> responseJson =
json.decode(response.body) as Map<String, dynamic>;
if (httpStatusCode == HttpStatus.ok) {
return DocumentSnapshot._(path, responseJson);
} else {
throw CarpServiceException.fromMap(httpStatusCode, responseJson);
}
}