From 5b6c5ada18c5fde32937c0bba3d401da389f1691 Mon Sep 17 00:00:00 2001 From: RyanSusana Date: Wed, 31 Jul 2024 18:23:03 +0200 Subject: [PATCH] Removed min and max on number --- .../main/java/com/elepy/annotations/Number.java | 11 ----------- .../com/elepy/models/options/NumberOptions.java | 16 +--------------- core/src/test/java/com/elepy/Resource.java | 12 +++++++++--- core/src/test/java/com/elepy/ResourceArray.java | 2 +- .../com/elepy/describers/SchemaUtilsTest.java | 3 --- docs/annotations/field/number.md | 4 ++-- docs/guides/custom-functionality.md | 8 +++++--- docs/main/getting-started.md | 6 ++++-- .../test/java/com/elepy/hibernate/Resource.java | 11 ++++++++--- .../test/java/com/elepy/mongo/fast/Resource.java | 11 ++++++++--- .../java/com/elepy/tests/basic/Resource.java | 12 +++++++++--- 11 files changed, 47 insertions(+), 49 deletions(-) diff --git a/core/src/main/java/com/elepy/annotations/Number.java b/core/src/main/java/com/elepy/annotations/Number.java index f134c74a..2966ba13 100644 --- a/core/src/main/java/com/elepy/annotations/Number.java +++ b/core/src/main/java/com/elepy/annotations/Number.java @@ -14,15 +14,4 @@ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE_USE}) public @interface Number { - /** - * @deprecated use Java Bean Validation instead - */ - @Deprecated(forRemoval = true) - float minimum() default Integer.MIN_VALUE; - - /** - * @deprecated use Java Bean Validation instead - */ - @Deprecated(forRemoval = true) - float maximum() default Integer.MAX_VALUE; } diff --git a/core/src/main/java/com/elepy/models/options/NumberOptions.java b/core/src/main/java/com/elepy/models/options/NumberOptions.java index 0e321ad6..0e0dd1b3 100644 --- a/core/src/main/java/com/elepy/models/options/NumberOptions.java +++ b/core/src/main/java/com/elepy/models/options/NumberOptions.java @@ -8,33 +8,19 @@ import java.lang.reflect.AnnotatedElement; public class NumberOptions implements Options { - private final float minimum; - private final float maximum; private final NumberType numberType; - public NumberOptions(float minimum, float maximum, NumberType numberType) { - this.minimum = minimum; - this.maximum = maximum; + public NumberOptions(NumberType numberType) { this.numberType = numberType; } public static NumberOptions of(AnnotatedElement field) { final Number annotation = Annotations.get(field, Number.class); return new NumberOptions( - annotation == null ? Integer.MIN_VALUE : annotation.minimum(), - annotation == null ? Integer.MAX_VALUE : annotation.maximum(), NumberType.guessType(ReflectionUtils.returnTypeOf(field) )); } - public float getMinimum() { - return minimum; - } - - public float getMaximum() { - return maximum; - } - public NumberType getNumberType() { return numberType; } diff --git a/core/src/test/java/com/elepy/Resource.java b/core/src/test/java/com/elepy/Resource.java index 9610ec61..7a07b001 100644 --- a/core/src/test/java/com/elepy/Resource.java +++ b/core/src/test/java/com/elepy/Resource.java @@ -5,6 +5,8 @@ import com.elepy.models.TextType; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Size; import java.math.BigDecimal; @@ -50,13 +52,17 @@ public class Resource { @TextArea private String minLen10MaxLen50; - @Number(minimum = 20) + @Number() + @Min(20) private BigDecimal numberMin20; - @Number(maximum = 40) + @Number() + @Max(40) private BigDecimal numberMax40; - @Number(minimum = 10, maximum = 50) + @Number() + @Min(10) + @Max(50) private BigDecimal numberMin10Max50; @Searchable diff --git a/core/src/test/java/com/elepy/ResourceArray.java b/core/src/test/java/com/elepy/ResourceArray.java index 7c3dd421..6abe90ae 100644 --- a/core/src/test/java/com/elepy/ResourceArray.java +++ b/core/src/test/java/com/elepy/ResourceArray.java @@ -29,7 +29,7 @@ public class ResourceArray { @Size(max = 2, min = 1) private List<@Size(min = 10) String> arrayStringMax2Min1TextWithMinimumLengthOf10; - private List<@Number(minimum = 10) Integer> arrayNumberMax2Min1NumberWithMinimumOf10; + private List<@Number Integer> arrayNumberMax2Min1NumberWithMinimumOf10; public List getArrayFileReference() { diff --git a/core/src/test/java/com/elepy/describers/SchemaUtilsTest.java b/core/src/test/java/com/elepy/describers/SchemaUtilsTest.java index 989df069..9f1f81a7 100644 --- a/core/src/test/java/com/elepy/describers/SchemaUtilsTest.java +++ b/core/src/test/java/com/elepy/describers/SchemaUtilsTest.java @@ -101,10 +101,7 @@ void testCorrectNumber() { final Schema schemaFromClass = new SchemaFactory().createDeepSchema(Resource.class); final Property property = schemaFromClass.getProperty("numberMin10Max50"); - final NumberOptions of = property.getOptions(); - assertThat(of.getMinimum()).isEqualTo(10); - assertThat(of.getMaximum()).isEqualTo(50); assertThat(property.getType()) .isEqualTo(NUMBER); } diff --git a/docs/annotations/field/number.md b/docs/annotations/field/number.md index 0819ef79..744cfac5 100644 --- a/docs/annotations/field/number.md +++ b/docs/annotations/field/number.md @@ -1,9 +1,9 @@ # @Number -This annotation signifies that a field is a number. It comes with three optional properties, minimum, maximum and value(NumberType). The minimum and maximum properties get asserted by the `ObjectEvaluator' +This annotation signifies that a field is a number. _Example_ ```java -@Number(minimum = 0, maximum = 1000, value = NumberType.DECIMAL) +@Number(value = NumberType.DECIMAL) private BigDecimal price; ``` __*Can only be used on Fields that extend `java.lang.Number`__ diff --git a/docs/guides/custom-functionality.md b/docs/guides/custom-functionality.md index 41917fba..59286918 100644 --- a/docs/guides/custom-functionality.md +++ b/docs/guides/custom-functionality.md @@ -34,15 +34,17 @@ public class Product { private String name; @Label("Product Price") - @Number(minimum = 0) + @Number private BigDecimal price; @Label("Amount of stock left") - @Number(minimum = 0) + @Number +@Min(0) private int stockLeft; @Label("Amount sold") - @Number(minimum = 0) + @Number +@Min(0) private int amountSold; // Getters and Setters diff --git a/docs/main/getting-started.md b/docs/main/getting-started.md index ba5f46f3..20b3a1d0 100644 --- a/docs/main/getting-started.md +++ b/docs/main/getting-started.md @@ -57,10 +57,12 @@ public class Product { @Unique private String name; - @Number(minimum = 0) + @Number +@Min(0) private BigDecimal price; - @Number(minimum = 0) + @Number +@Min(0) private int stockLeft; //Getters and Setters. I like to use Lombok to automate this :D diff --git a/hibernate/src/test/java/com/elepy/hibernate/Resource.java b/hibernate/src/test/java/com/elepy/hibernate/Resource.java index ff0025ec..036e1062 100644 --- a/hibernate/src/test/java/com/elepy/hibernate/Resource.java +++ b/hibernate/src/test/java/com/elepy/hibernate/Resource.java @@ -3,6 +3,8 @@ import com.elepy.annotations.Number; import com.elepy.annotations.*; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Size; import javax.persistence.Entity; @@ -42,13 +44,16 @@ public class Resource { @Size(min = 10, max = 50) private String minLen10MaxLen50; - @com.elepy.annotations.Number(minimum = 20) + @com.elepy.annotations.Number() +@Min(20) private BigDecimal numberMin20; - @com.elepy.annotations.Number(maximum = 40) + @com.elepy.annotations.Number() +@Max(40) private BigDecimal numberMax40; - @Number(minimum = 10, maximum = 50) + @Number() +@Min(10)@Max(50) private BigDecimal numberMin10Max50; @Searchable diff --git a/mongo/src/test/java/com/elepy/mongo/fast/Resource.java b/mongo/src/test/java/com/elepy/mongo/fast/Resource.java index e77453c6..13396331 100644 --- a/mongo/src/test/java/com/elepy/mongo/fast/Resource.java +++ b/mongo/src/test/java/com/elepy/mongo/fast/Resource.java @@ -6,6 +6,8 @@ import com.elepy.mongo.annotations.MongoIndex; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Size; import java.math.BigDecimal; @@ -46,13 +48,16 @@ public class Resource { @Size(min = 10, max = 50) private String minLen10MaxLen50; - @Number(minimum = 20) + @Number +@Min(20) private BigDecimal numberMin20; - @Number(maximum = 40) + @Number +@Max(40) private BigDecimal numberMax40; - @Number(minimum = 10, maximum = 50) + @Number() + @Min(10)@Max(50) private BigDecimal numberMin10Max50; @Searchable diff --git a/tests/src/main/java/com/elepy/tests/basic/Resource.java b/tests/src/main/java/com/elepy/tests/basic/Resource.java index a82f9927..2535d187 100644 --- a/tests/src/main/java/com/elepy/tests/basic/Resource.java +++ b/tests/src/main/java/com/elepy/tests/basic/Resource.java @@ -6,6 +6,8 @@ import com.elepy.http.HttpMethod; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Size; import javax.persistence.Entity; @@ -52,13 +54,17 @@ public class Resource { @Size(min = 10, max = 50) private String minLen10MaxLen50; - @Number(minimum = 20) + @Number + @Min(20) private BigDecimal numberMin20; - @Number(maximum = 40) + @Number + @Max(40) private BigDecimal numberMax40; - @Number(minimum = 10, maximum = 50) + @Number() + @Min(10) + @Max(50) private BigDecimal numberMin10Max50; @Searchable