Skip to content

Commit fff40ce

Browse files
authored
Merge pull request #260 from appwrite/dev
Dev
2 parents 4af5da4 + 72313d3 commit fff40ce

File tree

12 files changed

+167
-7
lines changed

12 files changed

+167
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 17.1.0
4+
5+
* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service
6+
* Add `gif` support to `ImageFormat` enum
7+
* Add `sequence` support to `Document` model
8+
39
## 17.0.2
410

511
* Add `gif` support to `ImageFormat` enum

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file:
2121

2222
```yml
2323
dependencies:
24-
appwrite: ^17.0.2
24+
appwrite: ^17.1.0
2525
```
2626
2727
You can install packages from the command line:

docs/examples/databases/create-document.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import 'package:appwrite/appwrite.dart';
22

33
Client client = Client()
44
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5-
.setSession('') // The user session to authenticate with
6-
.setKey('') //
7-
.setJWT('<YOUR_JWT>'); // Your secret JSON Web Token
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
86

97
Databases databases = Databases(client);
108

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:appwrite/appwrite.dart';
2+
3+
Client client = Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
Databases databases = Databases(client);
8+
9+
Document result = await databases.decrementDocumentAttribute(
10+
databaseId: '<DATABASE_ID>',
11+
collectionId: '<COLLECTION_ID>',
12+
documentId: '<DOCUMENT_ID>',
13+
attribute: '',
14+
value: 0, // optional
15+
min: 0, // optional
16+
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:appwrite/appwrite.dart';
2+
3+
Client client = Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
Databases databases = Databases(client);
8+
9+
Document result = await databases.incrementDocumentAttribute(
10+
databaseId: '<DATABASE_ID>',
11+
collectionId: '<COLLECTION_ID>',
12+
documentId: '<DOCUMENT_ID>',
13+
attribute: '',
14+
value: 0, // optional
15+
max: 0, // optional
16+
);

lib/services/databases.dart

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,64 @@ class Databases extends Service {
189189

190190
return res.data;
191191
}
192+
193+
/// Decrement a specific attribute of a document by a given value.
194+
Future<models.Document> decrementDocumentAttribute({
195+
required String databaseId,
196+
required String collectionId,
197+
required String documentId,
198+
required String attribute,
199+
double? value,
200+
double? min,
201+
}) async {
202+
final String apiPath =
203+
'/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'
204+
.replaceAll('{databaseId}', databaseId)
205+
.replaceAll('{collectionId}', collectionId)
206+
.replaceAll('{documentId}', documentId)
207+
.replaceAll('{attribute}', attribute);
208+
209+
final Map<String, dynamic> apiParams = {'value': value, 'min': min};
210+
211+
final Map<String, String> apiHeaders = {'content-type': 'application/json'};
212+
213+
final res = await client.call(
214+
HttpMethod.patch,
215+
path: apiPath,
216+
params: apiParams,
217+
headers: apiHeaders,
218+
);
219+
220+
return models.Document.fromMap(res.data);
221+
}
222+
223+
/// Increment a specific attribute of a document by a given value.
224+
Future<models.Document> incrementDocumentAttribute({
225+
required String databaseId,
226+
required String collectionId,
227+
required String documentId,
228+
required String attribute,
229+
double? value,
230+
double? max,
231+
}) async {
232+
final String apiPath =
233+
'/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'
234+
.replaceAll('{databaseId}', databaseId)
235+
.replaceAll('{collectionId}', collectionId)
236+
.replaceAll('{documentId}', documentId)
237+
.replaceAll('{attribute}', attribute);
238+
239+
final Map<String, dynamic> apiParams = {'value': value, 'max': max};
240+
241+
final Map<String, String> apiHeaders = {'content-type': 'application/json'};
242+
243+
final res = await client.call(
244+
HttpMethod.patch,
245+
path: apiPath,
246+
params: apiParams,
247+
headers: apiHeaders,
248+
);
249+
250+
return models.Document.fromMap(res.data);
251+
}
192252
}

lib/src/client_browser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
4040
'x-sdk-name': 'Flutter',
4141
'x-sdk-platform': 'client',
4242
'x-sdk-language': 'flutter',
43-
'x-sdk-version': '17.0.2',
43+
'x-sdk-version': '17.1.0',
4444
'X-Appwrite-Response-Format': '1.7.0',
4545
};
4646

lib/src/client_io.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ClientIO extends ClientBase with ClientMixin {
5858
'x-sdk-name': 'Flutter',
5959
'x-sdk-platform': 'client',
6060
'x-sdk-language': 'flutter',
61-
'x-sdk-version': '17.0.2',
61+
'x-sdk-version': '17.1.0',
6262
'X-Appwrite-Response-Format': '1.7.0',
6363
};
6464

lib/src/models/document.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class Document implements Model {
55
/// Document ID.
66
final String $id;
77

8+
/// Document automatically incrementing ID.
9+
final int $sequence;
10+
811
/// Collection ID.
912
final String $collectionId;
1013

@@ -24,6 +27,7 @@ class Document implements Model {
2427

2528
Document({
2629
required this.$id,
30+
required this.$sequence,
2731
required this.$collectionId,
2832
required this.$databaseId,
2933
required this.$createdAt,
@@ -35,6 +39,7 @@ class Document implements Model {
3539
factory Document.fromMap(Map<String, dynamic> map) {
3640
return Document(
3741
$id: map['\$id'].toString(),
42+
$sequence: map['\$sequence'],
3843
$collectionId: map['\$collectionId'].toString(),
3944
$databaseId: map['\$databaseId'].toString(),
4045
$createdAt: map['\$createdAt'].toString(),
@@ -47,6 +52,7 @@ class Document implements Model {
4752
Map<String, dynamic> toMap() {
4853
return {
4954
"\$id": $id,
55+
"\$sequence": $sequence,
5056
"\$collectionId": $collectionId,
5157
"\$databaseId": $databaseId,
5258
"\$createdAt": $createdAt,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: appwrite
2-
version: 17.0.2
2+
version: 17.1.0
33
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
44
homepage: https://appwrite.io
55
repository: https://github.com/appwrite/sdk-for-flutter

0 commit comments

Comments
 (0)