diff --git a/.github/badges/branches.svg b/.github/badges/branches.svg
index cc80306..971320a 100644
--- a/.github/badges/branches.svg
+++ b/.github/badges/branches.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/.github/badges/jacoco.svg b/.github/badges/jacoco.svg
index a90f0b0..4f41679 100644
--- a/.github/badges/jacoco.svg
+++ b/.github/badges/jacoco.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 8114f98..a93c102 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -19,7 +19,7 @@ plugins {
}
group = "io.github.verissimor.lib"
-version = System.getenv("RELEASE_VERSION") ?: "1.0.1-SNAPSHOT"
+version = System.getenv("RELEASE_VERSION") ?: "1.0.2-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/configuration/PageableWebFluxConfiguration.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/configuration/PageableWebFluxConfiguration.java
index 87c98b4..57e593f 100644
--- a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/configuration/PageableWebFluxConfiguration.java
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/configuration/PageableWebFluxConfiguration.java
@@ -2,6 +2,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.ReactivePageableHandlerMethodArgumentResolver;
+import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
@@ -12,4 +13,12 @@ public class PageableWebFluxConfiguration implements WebFluxConfigurer {
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
configurer.addCustomResolver(new ReactivePageableHandlerMethodArgumentResolver());
}
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping("/**")
+ .allowedOrigins("http://localhost:4400/") // only for tests
+ .allowedMethods("GET", "POST")
+ .allowedHeaders("*");
+ }
}
diff --git a/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcFieldParser.kt b/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcFieldParser.kt
index 1655428..e976b60 100644
--- a/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcFieldParser.kt
+++ b/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcFieldParser.kt
@@ -1,6 +1,9 @@
package io.github.verissimor.lib.r2dbcmagicfilter
+import io.github.verissimor.lib.jpamagicfilter.domain.FieldType
import io.github.verissimor.lib.jpamagicfilter.domain.FilterOperator
+import io.github.verissimor.lib.jpamagicfilter.domain.ParsedField
+import io.github.verissimor.lib.jpamagicfilter.toSingleString
import io.github.verissimor.lib.r2dbcmagicfilter.domain.R2dbcParsedField
import java.lang.reflect.Field
@@ -8,25 +11,37 @@ object R2dbcFieldParser {
fun parseField(field: String, value: Array?, clazz: Class<*>): R2dbcParsedField {
val normalized = normalize(field)
- val filterType = fieldToType(normalized, value)
- val resolvedFieldName = resolveFieldName(normalized, filterType)
+ val filterOperator = fieldToFilterOperator(normalized)
+ val resolvedFieldName = resolveFieldName(normalized, filterOperator)
val fieldClass: Field? = fieldToClass(resolvedFieldName, clazz)
- return R2dbcParsedField(filterType, resolvedFieldName, fieldClass)
+ val resolvedOperator = overloadFilterOperator(filterOperator, value, fieldClass)
+
+ return R2dbcParsedField(resolvedOperator, resolvedFieldName, fieldClass)
}
private fun normalize(field: String) = field.trim().replace("[]", "")
- private fun fieldToType(field: String, value: Array?): FilterOperator {
+ private fun fieldToFilterOperator(field: String): FilterOperator {
val type = FilterOperator.values()
.sortedByDescending { it.suffix.length }
.firstOrNull { field.contains(it.suffix) } ?: FilterOperator.EQUAL
- if (value != null && type == FilterOperator.EQUAL && value.size > 1) {
+ return type
+ }
+
+ private fun overloadFilterOperator(filterOperator: FilterOperator, value: Array?, fieldClass: Field?): FilterOperator {
+ val shouldTryOverload = value != null && filterOperator == FilterOperator.EQUAL
+ if (shouldTryOverload && value!!.size > 1) {
return FilterOperator.IN
}
- return type
+ val fieldType: FieldType? = ParsedField.getFieldType(fieldClass)
+ if (shouldTryOverload && fieldType == FieldType.NUMBER && value!!.toSingleString()!!.contains(",")) {
+ return FilterOperator.IN
+ }
+
+ return filterOperator
}
private fun resolveFieldName(field: String, type: FilterOperator?) =