-
Notifications
You must be signed in to change notification settings - Fork 8
Bugfix #8390, #8391 Added missing validation for fields in UpdateOrderPageAdmin dto. #1702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA new custom validation annotation and its corresponding validator were introduced to enforce specific rules on customer name and surname fields within the Changes
Sequence Diagram(s)sequenceDiagram
participant Admin as Admin User
participant Controller as Controller
participant DTO as UpdateOrderPageAdminDto
participant Validator as UpdateOrderPageAdminValidator
participant ValidationContext as ConstraintValidatorContext
Admin->>Controller: Submit UpdateOrderPageAdminDto
Controller->>Validator: Validate DTO (with @ValidUpdateOrderPageAdmin)
Validator->>DTO: Access customerName, customerSurname
alt customer info is null
Validator-->>Controller: Validation passes
else customer info present
alt Name or Surname invalid
Validator->>ValidationContext: Add constraint violation
Validator-->>Controller: Validation fails
else All fields valid
Validator-->>Controller: Validation passes
end
end
Controller-->>Admin: Return result
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
service-api/src/main/java/greencity/annotations/ValidUpdateOrderPageAdmin.java (1)
11-20
: Consider adding@Documented
and broadening the@Target
.
- Annotating the class with
@Documented
(fromjava.lang.annotation
) ensures the custom constraint appears in generated javadoc, which is standard practice for Bean-Validation annotations.- If you anticipate validating method parameters or constructors in future, extending
@Target
withPARAMETER
and/orANNOTATION_TYPE
now prevents another migration later.@@ -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) +@Target({ + ElementType.FIELD, + ElementType.METHOD, + ElementType.TYPE, + ElementType.PARAMETER, + ElementType.ANNOTATION_TYPE +}) +@Documented @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = {UpdateOrderPageAdminValidator.class})service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java (1)
34-40
: Avoid regex recompilation & duplicate literals.
String.matches(...)
recompiles the pattern on every call, and the literal error strings are duplicated.
A small refactor improves performance and maintainability:+import java.util.regex.Pattern; + public class UpdateOrderPageAdminValidator @@ + + private static final Pattern NAME_PATTERN = + Pattern.compile("^[A-Za-zА-Яа-я\\- '\\s]+$"); + @@ - } else if (!name.matches("^[A-Za-zА-Яа-я\\- '\\s]+$")) { + } else if (!NAME_PATTERN.matcher(name).matches()) { @@ - } else if (!surname.matches("^[A-Za-zА-Яа-я\\- '\\s]+$")) { + } else if (!NAME_PATTERN.matcher(surname).matches()) {Additionally, consider extracting the two message strings into
static final
constants (or a message-bundle key) to prevent future drift.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
service-api/src/main/java/greencity/annotations/ValidUpdateOrderPageAdmin.java
(1 hunks)service-api/src/main/java/greencity/dto/order/UpdateOrderPageAdminDto.java
(2 hunks)service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java
(1 hunks)service-api/src/test/java/greencity/validator/UpdateOrderPageAdminValidatorTest.java
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
service-api/src/main/java/greencity/annotations/ValidUpdateOrderPageAdmin.java (1)
service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java (1)
UpdateOrderPageAdminValidator
(9-61)
🔇 Additional comments (2)
service-api/src/main/java/greencity/dto/order/UpdateOrderPageAdminDto.java (1)
21-25
: Annotation placement looks good.
@ValidUpdateOrderPageAdmin
is applied at class-level, which matches the validator’s logic. No further action needed here.service-api/src/test/java/greencity/validator/UpdateOrderPageAdminValidatorTest.java (1)
39-53
: Add edge-case tests fornull
DTO andnull
userInfo.With the suggested null-guard in the validator, two quick tests ensure the behaviour is locked in:
@Test void validationPassesForNullDto() { assertTrue(validator.isValid(null, context)); } @Test void validationPassesForNullUserInfo() { UpdateOrderPageAdminDto dto = UpdateOrderPageAdminDto.builder().userInfoDto(null).build(); assertTrue(validator.isValid(dto, context)); }Including these keeps the test suite aligned with the Bean-Validation contract.
service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java
Outdated
Show resolved
Hide resolved
service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java
Outdated
Show resolved
Hide resolved
service-api/src/test/java/greencity/validator/UpdateOrderPageAdminValidatorTest.java
Outdated
Show resolved
Hide resolved
service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java
Outdated
Show resolved
Hide resolved
|
GreenCityUBS PR
Issue Link 📋
#8390
#8391
Changed
UpdateOrderPageAdminDto
;Summary by CodeRabbit