Skip to content

Commit

Permalink
Merge pull request #190 from eliasnogueira/fix-entity
Browse files Browse the repository at this point in the history
chore: fix amount decimal validator
  • Loading branch information
eliasnogueira authored Oct 16, 2024
2 parents db0d770 + 47bbe9f commit 4be600d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
25 changes: 16 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.10] - 16-10-2024

## Changed

- Fixed the `Simulation` entity by replacing the `@Min` and `@Max` in the `amount` field by `@DecimalMin` and
`@DecimalMax`

## [1.3.9] - 12-10-2024

## Changed
Expand All @@ -13,15 +20,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added ` <maven.compiler.proc>full</maven.compiler.proc>` to solve the JDK 23 + Lombok issues
- Updated Maven Wrapper
- Updated the following libraries
- `spring-boot-starter-parent -> 3.3.4`
- `maven-surefire-plugin -> 3.5.1`
- `modelmapper -> 3.2.1`
- `hibernate-jpamodelgen -> 6.6.1.Final`
- `h2 -> 2.3.232`
- `junit -> 5.11.2`
- `datafaker -> 2.4.0`
- `testcontainers -> 1.20.2`
- `commons-compress -> 1.27.1`
- `spring-boot-starter-parent -> 3.3.4`
- `maven-surefire-plugin -> 3.5.1`
- `modelmapper -> 3.2.1`
- `hibernate-jpamodelgen -> 6.6.1.Final`
- `h2 -> 2.3.232`
- `junit -> 5.11.2`
- `datafaker -> 2.4.0`
- `testcontainers -> 1.20.2`
- `commons-compress -> 1.27.1`

## [1.3.8] - 08-08-2024

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.eliasogueira.credit</groupId>
<artifactId>combined-credit-api</artifactId>
<version>1.13.9</version>
<version>1.13.10</version>

<distributionManagement>
<repository>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/eliasnogueira/credit/entity/Simulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
Expand Down Expand Up @@ -68,8 +70,8 @@ public class Simulation {
private String email;

@NotNull(message = "Amount cannot be empty")
@Min(value = 1000, message = "Amount must be equal or greater than $ 1.000")
@Max(value = 40000, message = "Amount must be equal or less than than $ 40.000")
@DecimalMin(value = "1000", message = "Amount must be equal or greater than $ 1.000")
@DecimalMax(value = "40000", message = "Amount must be equal or less than than $ 40.000")
private BigDecimal amount;

@NotNull(message = "Installments cannot be empty")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ public SimulationAssert hasValidInstallments() {
public SimulationAssert hasValidAmount() {
isNotNull();

var minimum = new BigDecimal("1.000");
var maximum = new BigDecimal("40.000");
var minimum = new BigDecimal("1000");
var maximum = new BigDecimal("40000");

if (actual.getAmount().compareTo(minimum) < 0 || actual.getAmount().compareTo(maximum) > 0) {
failWithMessage("Amount must be equal or greater than $ 1.000 or equal or less than than $ 40.000");
}
if (actual.getAmount().compareTo(minimum) < 0) failWithMessage("Amount must be equal or greater than $ 1.000");

if (actual.getAmount().compareTo(maximum) > 0)
failWithMessage("Amount must be equal or less than than $ 40.000");

return this;
}
Expand Down

0 comments on commit 4be600d

Please sign in to comment.