Skip to content

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

Merged
merged 12 commits into from
Jul 16, 2025

Conversation

BohdanLys
Copy link
Contributor

@BohdanLys BohdanLys commented Jun 12, 2025

GreenCityUBS PR

Issue Link 📋

#8390
#8391

Changed

  • Added validation for fields CustomerName and CustomerSurname in UpdateOrderPageAdminDto;
  • Added tests for the created validator;

Summary by CodeRabbit

  • New Features
    • Added enhanced validation for updating order pages in the admin panel, ensuring customer name and surname fields meet specific character and formatting requirements.
  • Bug Fixes
    • Improved error messaging for invalid customer name or surname entries during admin order updates.
  • Tests
    • Introduced comprehensive tests to verify the new validation logic for admin order updates.

Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Walkthrough

A new custom validation annotation and its corresponding validator were introduced to enforce specific rules on customer name and surname fields within the UpdateOrderPageAdminDto. The DTO was annotated to use this validation, and comprehensive unit tests were added to verify the validator's correctness across multiple scenarios.

Changes

File(s) Change Summary
.../annotations/ValidUpdateOrderPageAdmin.java Added new custom validation annotation interface for admin order page updates.
.../dto/order/UpdateOrderPageAdminDto.java Applied the @ValidUpdateOrderPageAdmin annotation to the DTO class.
.../validator/UpdateOrderPageAdminValidator.java Introduced validator class implementing validation logic for customer name and surname fields.
.../constant/ValidationConstant.java Added regex constant for validating names and surnames with Latin and Cyrillic letters and allowed symbols.
.../test/java/greencity/validator/UpdateOrderPageAdminValidatorTest.java Added unit tests for the new validator, covering valid and invalid customer name and surname cases.

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
Loading

Possibly related PRs

Suggested reviewers

  • maks741
  • ChernenkoVitaliy
  • oleksandra-bulhakova

Poem

In the land of code, new rules take flight,
Names and surnames checked for what’s right.
With annotations fresh and tests that gleam,
Validators guard the update stream.
Now admins’ orders pass the test—
Only the best, no less, no jest!
🛡️✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8880f4b and e04ccb1.

📒 Files selected for processing (1)
  • service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • service-api/src/main/java/greencity/validator/UpdateOrderPageAdminValidator.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.

  1. Annotating the class with @Documented (from java.lang.annotation) ensures the custom constraint appears in generated javadoc, which is standard practice for Bean-Validation annotations.
  2. If you anticipate validating method parameters or constructors in future, extending @Target with PARAMETER and/or ANNOTATION_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

📥 Commits

Reviewing files that changed from the base of the PR and between 71a14fb and 404f870.

📒 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 for null DTO and null 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.

Copy link

sonarqubecloud bot commented Jul 3, 2025

@BohdanLys BohdanLys requested a review from SashaPog July 3, 2025 08:01
@BohdanLys BohdanLys merged commit a6ef331 into dev Jul 16, 2025
5 checks passed
@BohdanLys BohdanLys deleted the bug/8390-8391/fix-missing-validation branch July 16, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
6 participants