Skip to content

fix: Fix block update bug #245

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 16 commits into from
Jul 14, 2025
Merged

fix: Fix block update bug #245

merged 16 commits into from
Jul 14, 2025

Conversation

lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented Jul 9, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Bug Fixes

    • Corrected the return type in documentation for deleting block-group associations.
    • Improved authorization checks when updating blocks to ensure only the owner can make changes.
  • New Features

    • Added filtering by block name and improved tag filtering in block listing.
    • Enhanced block deletion to also remove related block-group associations.
  • Tests

    • Enhanced tests to cover deletion of block-group associations, improving reliability of block deletion functionality.

Copy link

coderabbitai bot commented Jul 9, 2025

Walkthrough

A new method was added to the BlockGroupBlockMapper interface for deleting records by block ID. The BlockServiceImpl class was updated to use this method in its block deletion logic and to change its authorization checks. The BlockController and NotGroupDto were enhanced to support filtering by block name and to handle tags as a JSON string. The BlockMapper query was modified to use OR logic for filtering criteria. Corresponding unit tests were updated to mock and verify the new mapper behavior.

Changes

File(s) Change Summary
.../BlockGroupBlockMapper.java Added deleteByBlockId(Integer blockId) method; fixed Javadoc for deleteByGroupIdAndBlockId.
.../BlockServiceImpl.java deleteBlockById now returns result of deleting block-group relations; updated authorization in updateBlockById.
.../BlockServiceImplTest.java Added mock for BlockGroupBlockMapper; updated test to verify new deletion logic.
.../BlockController.java Added optional name_cn_contains parameter; changed tags handling to JSON encode if present.
.../model/dto/NotGroupDto.java Added name field; changed tags from String[] to String.
.../BlockMapper.java Modified findBlocksReturn query to use OR logic for filtering by label, name, createdBy, tags.

Poem

A mapper gained a method new,
To clear block ties with just a few.
Service logic changed its tune,
Checking users—none too soon!
Controller filters now expand,
Name and tags held in hand.
Tests confirm the changes all. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b18d29e and 7b7c3d3.

📒 Files selected for processing (1)
  • base/src/main/java/com/tinyengine/it/controller/BlockController.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base/src/main/java/com/tinyengine/it/controller/BlockController.java
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 auto-generate unit tests to generate unit tests for 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 414f7ba and e599d34.

📒 Files selected for processing (3)
  • base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java (2 hunks)
  • base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java (3 hunks)
🔇 Additional comments (6)
base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java (2)

97-97: LGTM: Javadoc correction

The return type documentation has been correctly updated from "list" to "Integer" to match the actual method signature.


102-108: LGTM: Well-implemented deletion method

The new deleteByBlockId method follows established patterns in the codebase:

  • Proper SQL parameterization prevents injection vulnerabilities
  • Clear method naming and documentation
  • Consistent return type with similar methods
  • Appropriate use of @Delete annotation
base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java (3)

30-30: LGTM: Proper import addition

The import for BlockGroupBlockMapper is correctly added to support the new mock dependency.


73-74: LGTM: Appropriate mock setup

The @Mock annotation for BlockGroupBlockMapper follows the established pattern in the test class.


117-117: LGTM: Correct test stub addition

The mock stub for blockGroupBlockMapper.deleteByBlockId(123) properly supports the updated service implementation and maintains test coverage.

base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java (1)

175-175: LGTM: Improved authorization check

The authorization logic has been appropriately updated to check blockResult.getOccupierBy() against the current user instead of comparing app IDs. This provides more granular and accurate access control based on actual block ownership.

Copy link

@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: 0

🧹 Nitpick comments (1)
base/src/main/java/com/tinyengine/it/controller/BlockController.java (1)

56-59: Remove unused import.

The Collectors import on line 59 is not used in the visible code and should be removed to keep imports clean.

import java.util.Arrays;
-import java.util.stream.Collectors;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e599d34 and b18d29e.

📒 Files selected for processing (3)
  • base/src/main/java/com/tinyengine/it/controller/BlockController.java (2 hunks)
  • base/src/main/java/com/tinyengine/it/mapper/BlockMapper.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/dto/NotGroupDto.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
base/src/main/java/com/tinyengine/it/controller/BlockController.java (1)
base/src/main/java/com/tinyengine/it/common/utils/JsonUtils.java (1)
  • JsonUtils (45-349)
🔇 Additional comments (5)
base/src/main/java/com/tinyengine/it/model/dto/NotGroupDto.java (2)

34-36: LGTM! Addition of name field enhances filtering capabilities.

The new name field with proper schema annotation allows filtering by block name, which aligns with the coordinated changes in the controller and mapper layers.


42-42: LGTM! Field type change aligns with JSON encoding approach.

The change from String[] to String for the tags field is consistent with the controller's new approach of JSON-encoding tag arrays before setting them on the DTO.

base/src/main/java/com/tinyengine/it/mapper/BlockMapper.java (1)

159-165: Critical: Confirm the OR-based filtering in findBlocksReturn is intentional

We didn’t find any existing tests or documentation that validate the switch from AND to OR logic in the mapper:

  • No unit or integration tests exercise BlockMapper.findBlocksReturn(...) directly.
  • Service-layer tests mock the mapper and don’t assert on SQL behavior.
  • Without coverage, the OR logic change may introduce unintended search results.

Please review and confirm that returning blocks matching any of the criteria (label, name, createdBy, or tags) is the desired behavior.

base/src/main/java/com/tinyengine/it/controller/BlockController.java (2)

260-266: LGTM! Addition of name parameter enhances filtering capabilities.

The new name_cn_contains parameter properly mapped to name extends the filtering functionality and is correctly set on the NotGroupDto object.


269-271: LGTM! JSON encoding approach handles tags properly.

The logic to JSON-encode the tags array when it's non-null and non-empty is appropriate and aligns with the DTO field type change from String[] to String. The JsonUtils.encode() method will handle the array-to-JSON conversion correctly.

@hexqi hexqi merged commit ad25aba into opentiny:develop Jul 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants