mirror of
https://github.com/appwrite/sdk-for-flutter.git
synced 2026-04-07 19:27:41 +00:00
@@ -1,5 +1,11 @@
|
||||
# Change Log
|
||||
|
||||
## 17.1.0
|
||||
|
||||
* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service
|
||||
* Add `gif` support to `ImageFormat` enum
|
||||
* Add `sequence` support to `Document` model
|
||||
|
||||
## 17.0.2
|
||||
|
||||
* Add `gif` support to `ImageFormat` enum
|
||||
|
||||
@@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file:
|
||||
|
||||
```yml
|
||||
dependencies:
|
||||
appwrite: ^17.0.2
|
||||
appwrite: ^17.1.0
|
||||
```
|
||||
|
||||
You can install packages from the command line:
|
||||
|
||||
@@ -2,9 +2,7 @@ import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setSession('') // The user session to authenticate with
|
||||
.setKey('') //
|
||||
.setJWT('<YOUR_JWT>'); // Your secret JSON Web Token
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Databases databases = Databases(client);
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Databases databases = Databases(client);
|
||||
|
||||
Document result = await databases.decrementDocumentAttribute(
|
||||
databaseId: '<DATABASE_ID>',
|
||||
collectionId: '<COLLECTION_ID>',
|
||||
documentId: '<DOCUMENT_ID>',
|
||||
attribute: '',
|
||||
value: 0, // optional
|
||||
min: 0, // optional
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Databases databases = Databases(client);
|
||||
|
||||
Document result = await databases.incrementDocumentAttribute(
|
||||
databaseId: '<DATABASE_ID>',
|
||||
collectionId: '<COLLECTION_ID>',
|
||||
documentId: '<DOCUMENT_ID>',
|
||||
attribute: '',
|
||||
value: 0, // optional
|
||||
max: 0, // optional
|
||||
);
|
||||
@@ -189,4 +189,64 @@ class Databases extends Service {
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/// Decrement a specific attribute of a document by a given value.
|
||||
Future<models.Document> decrementDocumentAttribute({
|
||||
required String databaseId,
|
||||
required String collectionId,
|
||||
required String documentId,
|
||||
required String attribute,
|
||||
double? value,
|
||||
double? min,
|
||||
}) async {
|
||||
final String apiPath =
|
||||
'/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'
|
||||
.replaceAll('{databaseId}', databaseId)
|
||||
.replaceAll('{collectionId}', collectionId)
|
||||
.replaceAll('{documentId}', documentId)
|
||||
.replaceAll('{attribute}', attribute);
|
||||
|
||||
final Map<String, dynamic> apiParams = {'value': value, 'min': min};
|
||||
|
||||
final Map<String, String> apiHeaders = {'content-type': 'application/json'};
|
||||
|
||||
final res = await client.call(
|
||||
HttpMethod.patch,
|
||||
path: apiPath,
|
||||
params: apiParams,
|
||||
headers: apiHeaders,
|
||||
);
|
||||
|
||||
return models.Document.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Increment a specific attribute of a document by a given value.
|
||||
Future<models.Document> incrementDocumentAttribute({
|
||||
required String databaseId,
|
||||
required String collectionId,
|
||||
required String documentId,
|
||||
required String attribute,
|
||||
double? value,
|
||||
double? max,
|
||||
}) async {
|
||||
final String apiPath =
|
||||
'/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'
|
||||
.replaceAll('{databaseId}', databaseId)
|
||||
.replaceAll('{collectionId}', collectionId)
|
||||
.replaceAll('{documentId}', documentId)
|
||||
.replaceAll('{attribute}', attribute);
|
||||
|
||||
final Map<String, dynamic> apiParams = {'value': value, 'max': max};
|
||||
|
||||
final Map<String, String> apiHeaders = {'content-type': 'application/json'};
|
||||
|
||||
final res = await client.call(
|
||||
HttpMethod.patch,
|
||||
path: apiPath,
|
||||
params: apiParams,
|
||||
headers: apiHeaders,
|
||||
);
|
||||
|
||||
return models.Document.fromMap(res.data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
|
||||
'x-sdk-name': 'Flutter',
|
||||
'x-sdk-platform': 'client',
|
||||
'x-sdk-language': 'flutter',
|
||||
'x-sdk-version': '17.0.2',
|
||||
'x-sdk-version': '17.1.0',
|
||||
'X-Appwrite-Response-Format': '1.7.0',
|
||||
};
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class ClientIO extends ClientBase with ClientMixin {
|
||||
'x-sdk-name': 'Flutter',
|
||||
'x-sdk-platform': 'client',
|
||||
'x-sdk-language': 'flutter',
|
||||
'x-sdk-version': '17.0.2',
|
||||
'x-sdk-version': '17.1.0',
|
||||
'X-Appwrite-Response-Format': '1.7.0',
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ class Document implements Model {
|
||||
/// Document ID.
|
||||
final String $id;
|
||||
|
||||
/// Document automatically incrementing ID.
|
||||
final int $sequence;
|
||||
|
||||
/// Collection ID.
|
||||
final String $collectionId;
|
||||
|
||||
@@ -24,6 +27,7 @@ class Document implements Model {
|
||||
|
||||
Document({
|
||||
required this.$id,
|
||||
required this.$sequence,
|
||||
required this.$collectionId,
|
||||
required this.$databaseId,
|
||||
required this.$createdAt,
|
||||
@@ -35,6 +39,7 @@ class Document implements Model {
|
||||
factory Document.fromMap(Map<String, dynamic> map) {
|
||||
return Document(
|
||||
$id: map['\$id'].toString(),
|
||||
$sequence: map['\$sequence'],
|
||||
$collectionId: map['\$collectionId'].toString(),
|
||||
$databaseId: map['\$databaseId'].toString(),
|
||||
$createdAt: map['\$createdAt'].toString(),
|
||||
@@ -47,6 +52,7 @@ class Document implements Model {
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"\$id": $id,
|
||||
"\$sequence": $sequence,
|
||||
"\$collectionId": $collectionId,
|
||||
"\$databaseId": $databaseId,
|
||||
"\$createdAt": $createdAt,
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name: appwrite
|
||||
version: 17.0.2
|
||||
version: 17.1.0
|
||||
description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API
|
||||
homepage: https://appwrite.io
|
||||
repository: https://github.com/appwrite/sdk-for-flutter
|
||||
|
||||
@@ -76,6 +76,7 @@ void main() {
|
||||
test('test method createDocument()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$sequence': 1,
|
||||
'\$collectionId': '5e5ea5c15117e',
|
||||
'\$databaseId': '5e5ea5c15117e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
@@ -101,6 +102,7 @@ void main() {
|
||||
test('test method getDocument()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$sequence': 1,
|
||||
'\$collectionId': '5e5ea5c15117e',
|
||||
'\$databaseId': '5e5ea5c15117e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
@@ -125,6 +127,7 @@ void main() {
|
||||
test('test method upsertDocument()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$sequence': 1,
|
||||
'\$collectionId': '5e5ea5c15117e',
|
||||
'\$databaseId': '5e5ea5c15117e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
@@ -150,6 +153,7 @@ void main() {
|
||||
test('test method updateDocument()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$sequence': 1,
|
||||
'\$collectionId': '5e5ea5c15117e',
|
||||
'\$databaseId': '5e5ea5c15117e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
@@ -186,5 +190,57 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('test method decrementDocumentAttribute()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$sequence': 1,
|
||||
'\$collectionId': '5e5ea5c15117e',
|
||||
'\$databaseId': '5e5ea5c15117e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$permissions': [],};
|
||||
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.patch,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
|
||||
final response = await databases.decrementDocumentAttribute(
|
||||
databaseId: '<DATABASE_ID>',
|
||||
collectionId: '<COLLECTION_ID>',
|
||||
documentId: '<DOCUMENT_ID>',
|
||||
attribute: '',
|
||||
);
|
||||
expect(response, isA<models.Document>());
|
||||
|
||||
});
|
||||
|
||||
test('test method incrementDocumentAttribute()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$sequence': 1,
|
||||
'\$collectionId': '5e5ea5c15117e',
|
||||
'\$databaseId': '5e5ea5c15117e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$permissions': [],};
|
||||
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.patch,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
|
||||
final response = await databases.incrementDocumentAttribute(
|
||||
databaseId: '<DATABASE_ID>',
|
||||
collectionId: '<COLLECTION_ID>',
|
||||
documentId: '<DOCUMENT_ID>',
|
||||
attribute: '',
|
||||
);
|
||||
expect(response, isA<models.Document>());
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
@@ -7,6 +7,7 @@ void main() {
|
||||
test('model', () {
|
||||
final model = Document(
|
||||
$id: '5e5ea5c16897e',
|
||||
$sequence: 1,
|
||||
$collectionId: '5e5ea5c15117e',
|
||||
$databaseId: '5e5ea5c15117e',
|
||||
$createdAt: '2020-10-15T06:38:00.000+00:00',
|
||||
@@ -19,6 +20,7 @@ void main() {
|
||||
final result = Document.fromMap(map);
|
||||
|
||||
expect(result.$id, '5e5ea5c16897e');
|
||||
expect(result.$sequence, 1);
|
||||
expect(result.$collectionId, '5e5ea5c15117e');
|
||||
expect(result.$databaseId, '5e5ea5c15117e');
|
||||
expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00');
|
||||
|
||||
Reference in New Issue
Block a user