Skip to content

Commit f53fe22

Browse files
committed
fix(book): add @NotNull and @min(0) validation to availableCopies in
BookCreateDTO availableCopies previously accepted null values and negative numbers without any validation error. Added @NotNull and @min(0) to enforce that the field is always provided and non-negative on book creation.
1 parent 661e22e commit f53fe22

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

readme_pdf.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
> Este documento é a versão técnica da documentação do projeto,
2+
> utilizada para geração do PDF via CI.
3+
14
# Library API — Spring Boot 4 + JWT + Docker + Observability
25

36
Backend production-ready projetado com foco em previsibilidade, observabilidade e isolamento de responsabilidades.

src/main/java/com/example/library/book/dto/BookCreateDTO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Set;
44

5+
import jakarta.validation.constraints.Min;
56
import jakarta.validation.constraints.NotBlank;
67
import jakarta.validation.constraints.NotEmpty;
78
import jakarta.validation.constraints.NotNull;
@@ -10,6 +11,7 @@
1011

1112
@Builder
1213
public record BookCreateDTO(
14+
1315
Long id,
1416

1517
@NotBlank
@@ -20,6 +22,9 @@ public record BookCreateDTO(
2022

2123
@NotNull
2224
Integer publicationYear,
25+
26+
@NotNull
27+
@Min(value = 0, message = "Available copies must be zero or greater")
2328
Integer availableCopies,
2429

2530
@NotNull

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spring:
1414
default-property-inclusion: non_null
1515

1616
profiles:
17-
active: ${SPRING_PROFILES_ACTIVE:prod}
17+
active: ${SPRING_PROFILES_ACTIVE:dev}
1818

1919
servlet:
2020
multipart:

0 commit comments

Comments
 (0)