Skip to content

Add inc/dec #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# 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
* Fix `convertTo()` method in `Document` and `Preferences` models to correctly accept `Map<String, dynamic>`

## 17.0.1

* Fix `devKeys` support by conditionally including credentials during requests

## 17.0.0

* Update `flutter_web_auth_2` dependency to version 4.1.0
Expand All @@ -22,7 +37,7 @@
## 15.0.2

* Avoid setting empty `User-Agent` header and only encode it when present.
* Update doc examples to use new multi-region endpoint: `https://&lt;REGION&gt;.cloud.appwrite.io/v1`.
* Update doc examples to use new multi-region endpoint: `https://<REGION>.cloud.appwrite.io/v1`.

## 15.0.1

Expand All @@ -34,7 +49,7 @@

* Encode `User-Agent` header to fix invalid HTTP header field value error.
* Breaking changes:
* Changed the typing of `AppwriteException`&#039;s response parameter from a `dynamic` object to an optional string (`?String`).
* Changed the typing of `AppwriteException`'s response parameter from a `dynamic` object to an optional string (`?String`).

## 14.0.0

Expand Down Expand Up @@ -180,8 +195,8 @@ https://github.com/appwrite/appwrite/blob/master/CHANGES.md
## 6.0.0
* Support for Appwrite 0.15
* **NEW** Phone authentication `account.createPhoneSession()`
* **BREAKING** `Database` -&gt; `Databases`
* **BREAKING** `account.createSession()` -&gt; `account.createEmailSession()`
* **BREAKING** `Database` -> `Databases`
* **BREAKING** `account.createSession()` -> `account.createEmailSession()`
* **BREAKING** `dateCreated` attribute removed from `Team`, `Execution`, `File` models
* **BREAKING** `dateCreated` and `dateUpdated` attribute removed from `Func`, `Deployment`, `Bucket` models
* **BREAKING** Realtime channels
Expand All @@ -192,7 +207,7 @@ https://github.com/appwrite/appwrite/blob/master/CHANGES.md

## 5.0.0
* Support for Appwrite 0.14
* **BREAKING** `account.delete()` -&gt; `account.updateStatus()`
* **BREAKING** `account.delete()` -> `account.updateStatus()`
* **BREAKING** Execution model `stdout` renamed to `response`
* **BREAKING** Membership model `name` renamed to `userName` and `email` renamed to `userEmail`
* Added `teamName` to Membership model
Expand All @@ -209,7 +224,7 @@ https://github.com/appwrite/appwrite/blob/master/CHANGES.md
* **BREAKING** **Tags** have been renamed to **Deployments**
* **BREAKING** `createFile` function expects Bucket ID as the first parameter
* **BREAKING** `createDeployment` and `createFile` functions expect an instance **InputFile** rather than the instance of **MultipartFile**
* **BREAKING** `list&lt;Entity&gt;` endpoints now contain a `total` attribute instead of `sum`
* **BREAKING** `list<Entity>` endpoints now contain a `total` attribute instead of `sum`
* `onProgress()` callback function for endpoints supporting file uploads
* Support for synchronous function executions
* Bug fixes and Improvements
Expand Down Expand Up @@ -270,7 +285,7 @@ https://github.com/appwrite/appwrite/blob/master/CHANGES.md

## 0.7.0
- Support for Appwrite 0.9
- Breaking - removed order type enum, now you should pass string &#039;ASC&#039; or &#039;DESC&#039;
- Breaking - removed order type enum, now you should pass string 'ASC' or 'DESC'
- Image Crop Gravity support in image preview service
- New endpoint in Account getSession to get session by ID
- Fix - issues with User-Agent when app name consisted of non-ASCII characters
Expand Down Expand Up @@ -305,7 +320,7 @@ https://github.com/appwrite/appwrite/blob/master/CHANGES.md

- Upgraded to Null-safety, minimum Dart SDK required 2.12.0 and minimum Flutter SDK version required 2.0.0
- Upgraded all underlying dependencies to null safe version
- All of Avatars service now return Future&lt;Response&gt;&lt;/Response&gt; instead of String like the Storage getFilePreview, getFileView and getFileDownload
- All of Avatars service now return Future<Response></Response> instead of String like the Storage getFilePreview, getFileView and getFileDownload
- Upgraded to Null-safety, minimum Dart SDK required 2.12.0
- Upgraded all underlying dependencies to null safe version

Expand Down Expand Up @@ -347,7 +362,7 @@ https://github.com/appwrite/appwrite/blob/master/CHANGES.md

## 0.2.3

- Fixed OAuth2 cookie bug, where a new session cookie couldn&#039;t overwrite an old cookie
- Fixed OAuth2 cookie bug, where a new session cookie couldn't overwrite an old cookie

## 0.2.2

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file:

```yml
dependencies:
appwrite: ^17.0.1
appwrite: ^17.1.0
```

You can install packages from the command line:
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/databases/create-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 16 additions & 0 deletions docs/examples/databases/decrement-document-attribute.md
Original file line number Diff line number Diff line change
@@ -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
);
16 changes: 16 additions & 0 deletions docs/examples/databases/increment-document-attribute.md
Original file line number Diff line number Diff line change
@@ -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
);
64 changes: 64 additions & 0 deletions lib/services/databases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class Databases extends Service {
return models.Document.fromMap(res.data);
}

/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create or update a Document. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
Expand Down Expand Up @@ -185,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);
}
}
2 changes: 1 addition & 1 deletion lib/src/client_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.1',
'x-sdk-version': '17.1.0',
'X-Appwrite-Response-Format': '1.7.0',
};

Expand Down
2 changes: 1 addition & 1 deletion lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.1',
'x-sdk-version': '17.1.0',
'X-Appwrite-Response-Format': '1.7.0',
};

Expand Down
3 changes: 2 additions & 1 deletion lib/src/enums/image_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ enum ImageFormat {
png(value: 'png'),
webp(value: 'webp'),
heic(value: 'heic'),
avif(value: 'avif');
avif(value: 'avif'),
gif(value: 'gif');

const ImageFormat({required this.value});

Expand Down
8 changes: 7 additions & 1 deletion lib/src/models/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Document({
required this.$id,
required this.$sequence,
required this.$collectionId,
required this.$databaseId,
required this.$createdAt,
Expand All @@ -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(),
Expand All @@ -47,6 +52,7 @@ class Document implements Model {
Map<String, dynamic> toMap() {
return {
"\$id": $id,
"\$sequence": $sequence,
"\$collectionId": $collectionId,
"\$databaseId": $databaseId,
"\$createdAt": $createdAt,
Expand All @@ -56,5 +62,5 @@ class Document implements Model {
};
}

T convertTo<T>(T Function(Map) fromJson) => fromJson(data);
T convertTo<T>(T Function(Map<String, dynamic>) fromJson) => fromJson(data);
}
2 changes: 1 addition & 1 deletion lib/src/models/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class Preferences implements Model {
return {"data": data};
}

T convertTo<T>(T Function(Map) fromJson) => fromJson(data);
T convertTo<T>(T Function(Map<String, dynamic>) fromJson) => fromJson(data);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: appwrite
version: 17.0.1
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
Expand Down
56 changes: 56 additions & 0 deletions test/services/databases_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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>());

});

});
}
Loading