Skip to content

Commit bbe7107

Browse files
committed
Add 1.8.x support
1 parent 30edd39 commit bbe7107

File tree

10 files changed

+512
-0
lines changed

10 files changed

+512
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.Databases;
4+
5+
Client client = new Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>"); // Your project ID
8+
9+
Databases databases = new Databases(client);
10+
11+
databases.decrementDocumentAttribute(
12+
"<DATABASE_ID>", // databaseId
13+
"<COLLECTION_ID>", // collectionId
14+
"<DOCUMENT_ID>", // documentId
15+
"", // attribute
16+
0, // value (optional)
17+
0, // min (optional)
18+
new CoroutineCallback<>((result, error) -> {
19+
if (error != null) {
20+
error.printStackTrace();
21+
return;
22+
}
23+
24+
Log.d("Appwrite", result.toString());
25+
})
26+
);
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.Databases;
4+
5+
Client client = new Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>"); // Your project ID
8+
9+
Databases databases = new Databases(client);
10+
11+
databases.incrementDocumentAttribute(
12+
"<DATABASE_ID>", // databaseId
13+
"<COLLECTION_ID>", // collectionId
14+
"<DOCUMENT_ID>", // documentId
15+
"", // attribute
16+
0, // value (optional)
17+
0, // max (optional)
18+
new CoroutineCallback<>((result, error) -> {
19+
if (error != null) {
20+
error.printStackTrace();
21+
return;
22+
}
23+
24+
Log.d("Appwrite", result.toString());
25+
})
26+
);
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.TablesDb;
4+
5+
Client client = new Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>"); // Your project ID
8+
9+
TablesDb tablesDb = new TablesDb(client);
10+
11+
tablesDb.decrementRowColumn(
12+
"<DATABASE_ID>", // databaseId
13+
"<TABLE_ID>", // tableId
14+
"<ROW_ID>", // rowId
15+
"", // column
16+
0, // value (optional)
17+
0, // min (optional)
18+
new CoroutineCallback<>((result, error) -> {
19+
if (error != null) {
20+
error.printStackTrace();
21+
return;
22+
}
23+
24+
Log.d("Appwrite", result.toString());
25+
})
26+
);
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.TablesDb;
4+
5+
Client client = new Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>"); // Your project ID
8+
9+
TablesDb tablesDb = new TablesDb(client);
10+
11+
tablesDb.incrementRowColumn(
12+
"<DATABASE_ID>", // databaseId
13+
"<TABLE_ID>", // tableId
14+
"<ROW_ID>", // rowId
15+
"", // column
16+
0, // value (optional)
17+
0, // max (optional)
18+
new CoroutineCallback<>((result, error) -> {
19+
if (error != null) {
20+
error.printStackTrace();
21+
return;
22+
}
23+
24+
Log.d("Appwrite", result.toString());
25+
})
26+
);
27+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import io.appwrite.Client
2+
import io.appwrite.coroutines.CoroutineCallback
3+
import io.appwrite.services.Databases
4+
5+
val client = Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
9+
val databases = Databases(client)
10+
11+
val result = databases.decrementDocumentAttribute(
12+
databaseId = "<DATABASE_ID>",
13+
collectionId = "<COLLECTION_ID>",
14+
documentId = "<DOCUMENT_ID>",
15+
attribute = "",
16+
value = 0, // (optional)
17+
min = 0, // (optional)
18+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import io.appwrite.Client
2+
import io.appwrite.coroutines.CoroutineCallback
3+
import io.appwrite.services.Databases
4+
5+
val client = Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
9+
val databases = Databases(client)
10+
11+
val result = databases.incrementDocumentAttribute(
12+
databaseId = "<DATABASE_ID>",
13+
collectionId = "<COLLECTION_ID>",
14+
documentId = "<DOCUMENT_ID>",
15+
attribute = "",
16+
value = 0, // (optional)
17+
max = 0, // (optional)
18+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import io.appwrite.Client
2+
import io.appwrite.coroutines.CoroutineCallback
3+
import io.appwrite.services.TablesDb
4+
5+
val client = Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
9+
val tablesDb = TablesDb(client)
10+
11+
val result = tablesDb.decrementRowColumn(
12+
databaseId = "<DATABASE_ID>",
13+
tableId = "<TABLE_ID>",
14+
rowId = "<ROW_ID>",
15+
column = "",
16+
value = 0, // (optional)
17+
min = 0, // (optional)
18+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import io.appwrite.Client
2+
import io.appwrite.coroutines.CoroutineCallback
3+
import io.appwrite.services.TablesDb
4+
5+
val client = Client(context)
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
9+
val tablesDb = TablesDb(client)
10+
11+
val result = tablesDb.incrementRowColumn(
12+
databaseId = "<DATABASE_ID>",
13+
tableId = "<TABLE_ID>",
14+
rowId = "<ROW_ID>",
15+
column = "",
16+
value = 0, // (optional)
17+
max = 0, // (optional)
18+
)

library/src/main/java/io/appwrite/services/Databases.kt

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,180 @@ class Databases(client: Client) : Service(client) {
443443
}
444444

445445

446+
/**
447+
* Decrement a specific attribute of a document by a given value.
448+
*
449+
* @param databaseId Database ID.
450+
* @param collectionId Collection ID.
451+
* @param documentId Document ID.
452+
* @param attribute Attribute key.
453+
* @param value Value to increment the attribute by. The value must be a number.
454+
* @param min Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown.
455+
* @return [io.appwrite.models.Document<T>]
456+
*/
457+
@Deprecated(
458+
message = "This API has been deprecated since 1.8.0. Please use `TablesDb.decrementRowColumn` instead.",
459+
replaceWith = ReplaceWith("io.appwrite.services.TablesDb.decrementRowColumn"),
460+
since = "1.8.0"
461+
)
462+
@JvmOverloads
463+
suspend fun <T> decrementDocumentAttribute(
464+
databaseId: String,
465+
collectionId: String,
466+
documentId: String,
467+
attribute: String,
468+
value: Double? = null,
469+
min: Double? = null,
470+
nestedType: Class<T>,
471+
): io.appwrite.models.Document<T> {
472+
val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement"
473+
.replace("{databaseId}", databaseId)
474+
.replace("{collectionId}", collectionId)
475+
.replace("{documentId}", documentId)
476+
.replace("{attribute}", attribute)
477+
478+
val apiParams = mutableMapOf<String, Any?>(
479+
"value" to value,
480+
"min" to min,
481+
)
482+
val apiHeaders = mutableMapOf<String, String>(
483+
"content-type" to "application/json",
484+
)
485+
val converter: (Any) -> io.appwrite.models.Document<T> = {
486+
@Suppress("UNCHECKED_CAST")
487+
io.appwrite.models.Document.from(map = it as Map<String, Any>, nestedType)
488+
}
489+
return client.call(
490+
"PATCH",
491+
apiPath,
492+
apiHeaders,
493+
apiParams,
494+
responseType = classOf(),
495+
converter,
496+
)
497+
}
498+
499+
/**
500+
* Decrement a specific attribute of a document by a given value.
501+
*
502+
* @param databaseId Database ID.
503+
* @param collectionId Collection ID.
504+
* @param documentId Document ID.
505+
* @param attribute Attribute key.
506+
* @param value Value to increment the attribute by. The value must be a number.
507+
* @param min Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown.
508+
* @return [io.appwrite.models.Document<T>]
509+
*/
510+
@Deprecated(
511+
message = "This API has been deprecated since 1.8.0. Please use `TablesDb.decrementRowColumn` instead.",
512+
replaceWith = ReplaceWith("io.appwrite.services.TablesDb.decrementRowColumn"),
513+
since = "1.8.0"
514+
)
515+
@JvmOverloads
516+
@Throws(AppwriteException::class)
517+
suspend fun decrementDocumentAttribute(
518+
databaseId: String,
519+
collectionId: String,
520+
documentId: String,
521+
attribute: String,
522+
value: Double? = null,
523+
min: Double? = null,
524+
): io.appwrite.models.Document<Map<String, Any>> = decrementDocumentAttribute(
525+
databaseId,
526+
collectionId,
527+
documentId,
528+
attribute,
529+
value,
530+
min,
531+
nestedType = classOf(),
532+
)
533+
534+
/**
535+
* Increment a specific attribute of a document by a given value.
536+
*
537+
* @param databaseId Database ID.
538+
* @param collectionId Collection ID.
539+
* @param documentId Document ID.
540+
* @param attribute Attribute key.
541+
* @param value Value to increment the attribute by. The value must be a number.
542+
* @param max Maximum value for the attribute. If the current value is greater than this value, an error will be thrown.
543+
* @return [io.appwrite.models.Document<T>]
544+
*/
545+
@Deprecated(
546+
message = "This API has been deprecated since 1.8.0. Please use `TablesDb.incrementRowColumn` instead.",
547+
replaceWith = ReplaceWith("io.appwrite.services.TablesDb.incrementRowColumn"),
548+
since = "1.8.0"
549+
)
550+
@JvmOverloads
551+
suspend fun <T> incrementDocumentAttribute(
552+
databaseId: String,
553+
collectionId: String,
554+
documentId: String,
555+
attribute: String,
556+
value: Double? = null,
557+
max: Double? = null,
558+
nestedType: Class<T>,
559+
): io.appwrite.models.Document<T> {
560+
val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment"
561+
.replace("{databaseId}", databaseId)
562+
.replace("{collectionId}", collectionId)
563+
.replace("{documentId}", documentId)
564+
.replace("{attribute}", attribute)
565+
566+
val apiParams = mutableMapOf<String, Any?>(
567+
"value" to value,
568+
"max" to max,
569+
)
570+
val apiHeaders = mutableMapOf<String, String>(
571+
"content-type" to "application/json",
572+
)
573+
val converter: (Any) -> io.appwrite.models.Document<T> = {
574+
@Suppress("UNCHECKED_CAST")
575+
io.appwrite.models.Document.from(map = it as Map<String, Any>, nestedType)
576+
}
577+
return client.call(
578+
"PATCH",
579+
apiPath,
580+
apiHeaders,
581+
apiParams,
582+
responseType = classOf(),
583+
converter,
584+
)
585+
}
586+
587+
/**
588+
* Increment a specific attribute of a document by a given value.
589+
*
590+
* @param databaseId Database ID.
591+
* @param collectionId Collection ID.
592+
* @param documentId Document ID.
593+
* @param attribute Attribute key.
594+
* @param value Value to increment the attribute by. The value must be a number.
595+
* @param max Maximum value for the attribute. If the current value is greater than this value, an error will be thrown.
596+
* @return [io.appwrite.models.Document<T>]
597+
*/
598+
@Deprecated(
599+
message = "This API has been deprecated since 1.8.0. Please use `TablesDb.incrementRowColumn` instead.",
600+
replaceWith = ReplaceWith("io.appwrite.services.TablesDb.incrementRowColumn"),
601+
since = "1.8.0"
602+
)
603+
@JvmOverloads
604+
@Throws(AppwriteException::class)
605+
suspend fun incrementDocumentAttribute(
606+
databaseId: String,
607+
collectionId: String,
608+
documentId: String,
609+
attribute: String,
610+
value: Double? = null,
611+
max: Double? = null,
612+
): io.appwrite.models.Document<Map<String, Any>> = incrementDocumentAttribute(
613+
databaseId,
614+
collectionId,
615+
documentId,
616+
attribute,
617+
value,
618+
max,
619+
nestedType = classOf(),
620+
)
621+
446622
}

0 commit comments

Comments
 (0)