diff --git a/templates/android/library/src/main/java/io/appwrite/Query.kt.twig b/templates/android/library/src/main/java/io/appwrite/Query.kt.twig index 2865cf76b..2bbb0f604 100644 --- a/templates/android/library/src/main/java/io/appwrite/Query.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/Query.kt.twig @@ -1,7 +1,9 @@ package {{ sdk.namespace | caseDot }} +import com.google.gson.Gson + class Query( - val method: String + val method: String, val attribute: String? = null, val values: List? = null, ) { @@ -52,9 +54,9 @@ class Query( fun or(queries: List) = Query("or", null, queries) - private fun parseValue(value: Any): Any { + private fun parseValue(value: Any): List { return when (value) { - is List<*> -> value + is List<*> -> value as List else -> listOf(value) } } diff --git a/templates/dart/lib/package.dart.twig b/templates/dart/lib/package.dart.twig index 648964076..9f57a7511 100644 --- a/templates/dart/lib/package.dart.twig +++ b/templates/dart/lib/package.dart.twig @@ -7,6 +7,7 @@ library {{ language.params.packageName }}; import 'dart:async'; import 'dart:typed_data'; +import 'dart:convert'; import 'src/enums.dart'; import 'src/service.dart'; diff --git a/templates/dart/lib/query.dart.twig b/templates/dart/lib/query.dart.twig index 78e3ef229..77e7ab3b9 100644 --- a/templates/dart/lib/query.dart.twig +++ b/templates/dart/lib/query.dart.twig @@ -1,6 +1,5 @@ part of {{ language.params.packageName }}; -import 'dart:convert'; /// Helper class to generate query strings. class Query { diff --git a/templates/flutter/lib/package.dart.twig b/templates/flutter/lib/package.dart.twig index 919d34d5c..e777f5b5e 100644 --- a/templates/flutter/lib/package.dart.twig +++ b/templates/flutter/lib/package.dart.twig @@ -7,6 +7,8 @@ library {{ language.params.packageName }}; import 'dart:async'; import 'dart:typed_data'; +import 'dart:convert'; + import 'src/enums.dart'; import 'src/service.dart'; import 'src/input_file.dart'; diff --git a/tests/Base.php b/tests/Base.php index b4a1d2f10..fd0892737 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -67,29 +67,29 @@ abstract class Base extends TestCase ]; protected const QUERY_HELPER_RESPONSES = [ - '{ "method": "equal", "attribute": "released", "values": [true]}', - '{ "method": "equal", "attribute": "title", "values": ["Spiderman", "Dr. Strange"]}', - '{ "method": "notEqual", "attribute": "title", "values": ["Spiderman"]}', - '{ "method": "lessThan", "attribute": "releasedYear", "values": [1990]}', - '{ "method": "greaterThan", "attribute": "releasedYear", "values": [1990]}', - '{ "method": "search", "attribute": "name", "values": ["john"]}', - '{ "method": "isNull", "attribute": "name"}', - '{ "method": "isNotNull", "attribute": "name"}', - '{ "method": "between", "attribute": "age", "values": [50, 100]}', - '{ "method": "between", "attribute": "age", "values": [50.5, 100.5]}', - '{ "method": "between", "attribute": "name", "values": ["Anna", "Brad"]}', - '{ "method": "startsWith", "attribute": "name", "values": ["Ann"]}', - '{ "method": "endsWith", "attribute": "name", "values": ["nne"]}', - '{ "method": "select", "values": [["name", "age"]]}', - '{ "method": "orderAsc", "attribute": "title"}', - '{ "method": "orderDesc", "attribute": "title"}', - '{ "method": "cursorAfter", "values": ["my_movie_id"]}', - '{ "method": "cursorBefore", "values": ["my_movie_id"]}', - '{ "method": "limit", "values": [50]}', - '{ "method": "offset", "values": [20]}', - '{ "method": "contains", "attribute": "title", "values": ["Spider"] }', - '{ "method": "contains", "attribute": "labels", "values": ["first"] }', - '{ "method": "or", "values": [{ "method": "equal", "attribute": "released", "values": [true] }, { "method": "lessThan", "attribute": "releasedYear", "values": [1990] }] }', + '{"method":"equal","attribute":"released","values":[true]}', + '{"method":"equal","attribute":"title","values":["Spiderman","Dr. Strange"]}', + '{"method":"notEqual","attribute":"title","values":["Spiderman"]}', + '{"method":"lessThan","attribute":"releasedYear","values":[1990]}', + '{"method":"greaterThan","attribute":"releasedYear","values":[1990]}', + '{"method":"search","attribute":"name","values":["john"]}', + '{"method":"isNull","attribute":"name"}', + '{"method":"isNotNull","attribute":"name"}', + '{"method":"between","attribute":"age","values":[50,100]}', + '{"method":"between","attribute":"age","values":[50.5,100.5]}', + '{"method":"between","attribute":"name","values":["Anna","Brad"]}', + '{"method":"startsWith","attribute":"name","values":["Ann"]}', + '{"method":"endsWith","attribute":"name","values":["nne"]}', + '{"method":"select","values":["name","age"]}', + '{"method":"orderAsc","attribute":"title"}', + '{"method":"orderDesc","attribute":"title"}', + '{"method":"cursorAfter","values":["my_movie_id"]}', + '{"method":"cursorBefore","values":["my_movie_id"]}', + '{"method":"limit","values":[50]}', + '{"method":"offset","values":[20]}', + '{"method":"contains","attribute":"title","values":["Spider"]}', + '{"method":"contains","attribute":"labels","values":["first"]}', + '{"method":"or","values":[{"method":"equal","attribute":"released","values":[true]},{"method":"lessThan","attribute":"releasedYear","values":[1990]}]}', ]; protected const PERMISSION_HELPER_RESPONSES = [ diff --git a/tests/languages/android/Tests.kt b/tests/languages/android/Tests.kt index ad756b0c0..38f02f28a 100644 --- a/tests/languages/android/Tests.kt +++ b/tests/languages/android/Tests.kt @@ -188,9 +188,9 @@ class ServiceTest { writeToFile(Query.cursorBefore("my_movie_id").toString()) writeToFile(Query.limit(50).toString()) writeToFile(Query.offset(20).toString()) - writeToFile(Query.contains("title", ["Spider"]).toString()) - writeToFile(Query.contains("labels", ["first"]).toString()) - writeToFile(Query.or(listOf(Query.equal("released", listOf(true)), Query.lessThan("releasedYear", 1990))) + writeToFile(Query.contains("title", listOf("Spider")).toString()) + writeToFile(Query.contains("labels", listOf("first")).toString()) + writeToFile(Query.or(listOf(Query.equal("released", listOf(true)), Query.lessThan("releasedYear", 1990))).toString()) // Permission & Roles helper tests writeToFile(Permission.read(Role.any())) diff --git a/tests/languages/dart/tests.dart b/tests/languages/dart/tests.dart index d4ed7e889..eaf43c79b 100644 --- a/tests/languages/dart/tests.dart +++ b/tests/languages/dart/tests.dart @@ -125,6 +125,12 @@ void main() async { print(Query.cursorBefore("my_movie_id")); print(Query.limit(50)); print(Query.offset(20)); + print(Query.contains("title", "Spider")); + print(Query.contains("labels", "first")); + print(Query.or([ + Query.equal("released", true), + Query.lessThan("releasedYear", 1990) + ])); // Permission & Role helper tests print(Permission.read(Role.any())); diff --git a/tests/languages/flutter/tests.dart b/tests/languages/flutter/tests.dart index 4553cab3b..3e06b8666 100644 --- a/tests/languages/flutter/tests.dart +++ b/tests/languages/flutter/tests.dart @@ -159,6 +159,12 @@ void main() async { print(Query.cursorBefore("my_movie_id")); print(Query.limit(50)); print(Query.offset(20)); + print(Query.contains("title", "Spider")); + print(Query.contains("labels", "first")); + print(Query.or([ + Query.equal("released", true), + Query.lessThan("releasedYear", 1990) + ])); // Permission & Role helper tests print(Permission.read(Role.any()));