diff --git a/CHANGELOG.md b/CHANGELOG.md index 8406e63..38d0c4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,23 @@ # Change Log +## 8.2.0 + +* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service +* Add `gif` support to `ImageFormat` enum +* Add `sequence` support to `Document` model + +## 8.1.0 + +* Add `devKeys` support to `Client` service +* Add `upsertDocument` support to `Databases` service + ## 8.0.0 * Add `token` param to `getFilePreview` and `getFileView` for File tokens usage * Update default `quality` for `getFilePreview` from 0 to -1 * Remove `Gif` from ImageFormat enum -* Remove `search` param from `listExecutions` method \ No newline at end of file +* Remove `search` param from `listExecutions` method + +## 7.0.1 + +* Fix requests failing by removing `Content-Type` header from `GET` and `HEAD` requests diff --git a/README.md b/README.md index 6bfc46c..745f21c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:8.1.0") +implementation("io.appwrite:sdk-for-android:8.2.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 8.1.0 + 8.2.0 ``` diff --git a/docs/examples/java/databases/create-document.md b/docs/examples/java/databases/create-document.md index 7fb129b..4804d75 100644 --- a/docs/examples/java/databases/create-document.md +++ b/docs/examples/java/databases/create-document.md @@ -4,9 +4,7 @@ import io.appwrite.services.Databases; Client client = new Client(context) .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setSession("") // The user session to authenticate with - .setKey("") // - .setJWT(""); // Your secret JSON Web Token + .setProject(""); // Your project ID Databases databases = new Databases(client); diff --git a/docs/examples/java/databases/decrement-document-attribute.md b/docs/examples/java/databases/decrement-document-attribute.md new file mode 100644 index 0000000..de6a4ab --- /dev/null +++ b/docs/examples/java/databases/decrement-document-attribute.md @@ -0,0 +1,27 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Databases; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Databases databases = new Databases(client); + +databases.decrementDocumentAttribute( + "", // databaseId + "", // collectionId + "", // documentId + "", // attribute + 0, // value (optional) + 0, // min (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + diff --git a/docs/examples/java/databases/increment-document-attribute.md b/docs/examples/java/databases/increment-document-attribute.md new file mode 100644 index 0000000..94ffa9d --- /dev/null +++ b/docs/examples/java/databases/increment-document-attribute.md @@ -0,0 +1,27 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Databases; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Databases databases = new Databases(client); + +databases.incrementDocumentAttribute( + "", // databaseId + "", // collectionId + "", // documentId + "", // attribute + 0, // value (optional) + 0, // max (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + diff --git a/docs/examples/kotlin/databases/create-document.md b/docs/examples/kotlin/databases/create-document.md index 0bafb31..849a636 100644 --- a/docs/examples/kotlin/databases/create-document.md +++ b/docs/examples/kotlin/databases/create-document.md @@ -4,9 +4,7 @@ import io.appwrite.services.Databases val client = Client(context) .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setSession("") // The user session to authenticate with - .setKey("") // - .setJWT("") // Your secret JSON Web Token + .setProject("") // Your project ID val databases = Databases(client) diff --git a/docs/examples/kotlin/databases/decrement-document-attribute.md b/docs/examples/kotlin/databases/decrement-document-attribute.md new file mode 100644 index 0000000..c500fa8 --- /dev/null +++ b/docs/examples/kotlin/databases/decrement-document-attribute.md @@ -0,0 +1,18 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Databases + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val databases = Databases(client) + +val result = databases.decrementDocumentAttribute( + databaseId = "", + collectionId = "", + documentId = "", + attribute = "", + value = 0, // (optional) + min = 0, // (optional) +) \ No newline at end of file diff --git a/docs/examples/kotlin/databases/increment-document-attribute.md b/docs/examples/kotlin/databases/increment-document-attribute.md new file mode 100644 index 0000000..0ae6b02 --- /dev/null +++ b/docs/examples/kotlin/databases/increment-document-attribute.md @@ -0,0 +1,18 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Databases + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val databases = Databases(client) + +val result = databases.incrementDocumentAttribute( + databaseId = "", + collectionId = "", + documentId = "", + attribute = "", + value = 0, // (optional) + max = 0, // (optional) +) \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 5f12d7f..bf0480f 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -87,7 +87,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "8.1.0", + "x-sdk-version" to "8.2.0", "x-appwrite-response-format" to "1.7.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/enums/ImageFormat.kt b/library/src/main/java/io/appwrite/enums/ImageFormat.kt index c3dea06..8e74806 100644 --- a/library/src/main/java/io/appwrite/enums/ImageFormat.kt +++ b/library/src/main/java/io/appwrite/enums/ImageFormat.kt @@ -14,7 +14,9 @@ enum class ImageFormat(val value: String) { @SerializedName("heic") HEIC("heic"), @SerializedName("avif") - AVIF("avif"); + AVIF("avif"), + @SerializedName("gif") + GIF("gif"); override fun toString() = value } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Document.kt b/library/src/main/java/io/appwrite/models/Document.kt index 01204de..c0dfe61 100644 --- a/library/src/main/java/io/appwrite/models/Document.kt +++ b/library/src/main/java/io/appwrite/models/Document.kt @@ -13,6 +13,12 @@ data class Document( @SerializedName("\$id") val id: String, + /** + * Document automatically incrementing ID. + */ + @SerializedName("\$sequence") + val sequence: Long, + /** * Collection ID. */ @@ -51,6 +57,7 @@ data class Document( ) { fun toMap(): Map = mapOf( "\$id" to id as Any, + "\$sequence" to sequence as Any, "\$collectionId" to collectionId as Any, "\$databaseId" to databaseId as Any, "\$createdAt" to createdAt as Any, @@ -62,6 +69,7 @@ data class Document( companion object { operator fun invoke( id: String, + sequence: Long, collectionId: String, databaseId: String, createdAt: String, @@ -70,6 +78,7 @@ data class Document( data: Map ) = Document>( id, + sequence, collectionId, databaseId, createdAt, @@ -84,6 +93,7 @@ data class Document( nestedType: Class ) = Document( id = map["\$id"] as String, + sequence = (map["\$sequence"] as Number).toLong(), collectionId = map["\$collectionId"] as String, databaseId = map["\$databaseId"] as String, createdAt = map["\$createdAt"] as String, diff --git a/library/src/main/java/io/appwrite/services/Databases.kt b/library/src/main/java/io/appwrite/services/Databases.kt index 2601af2..edc10f5 100644 --- a/library/src/main/java/io/appwrite/services/Databases.kt +++ b/library/src/main/java/io/appwrite/services/Databases.kt @@ -212,7 +212,7 @@ class Databases(client: Client) : Service(client) { ) /** - * 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) API or directly from your database console. + * **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) API or directly from your database console. * * @param databaseId Database ID. * @param collectionId Collection ID. @@ -257,7 +257,7 @@ class Databases(client: Client) : Service(client) { } /** - * 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) API or directly from your database console. + * **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) API or directly from your database console. * * @param databaseId Database ID. * @param collectionId Collection ID. @@ -388,4 +388,160 @@ class Databases(client: Client) : Service(client) { } + /** + * Decrement a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to decrement the attribute by. The value must be a number. + * @param min Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun decrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + min: Double? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + .replace("{attribute}", attribute) + + val apiParams = mutableMapOf( + "value" to value, + "min" to min, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Decrement a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to decrement the attribute by. The value must be a number. + * @param min Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun decrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + min: Double? = null, + ): io.appwrite.models.Document> = decrementDocumentAttribute( + databaseId, + collectionId, + documentId, + attribute, + value, + min, + nestedType = classOf(), + ) + + /** + * Increment a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to increment the attribute by. The value must be a number. + * @param max Maximum value for the attribute. If the current value is greater than this value, an error will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun incrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + max: Double? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + .replace("{attribute}", attribute) + + val apiParams = mutableMapOf( + "value" to value, + "max" to max, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Increment a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to increment the attribute by. The value must be a number. + * @param max Maximum value for the attribute. If the current value is greater than this value, an error will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun incrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + max: Double? = null, + ): io.appwrite.models.Document> = incrementDocumentAttribute( + databaseId, + collectionId, + documentId, + attribute, + value, + max, + nestedType = classOf(), + ) + } \ No newline at end of file