Skip to content

fix: Fix page create and componet library mapper #246

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

Conversation

lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented Jul 16, 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
  • [x ] No

Other information

Summary by CodeRabbit

  • Refactor

    • Improved database field mapping for several entities to clarify column associations.
    • Updated SQL queries for component library operations to enhance clarity and maintainability.
    • Changed the type of tenant identifiers from integer to string.
    • Adjusted the page creation API to accept raw HTTP requests for more flexible input handling.
  • Tests

    • Updated tests to align with the revised page creation API input method.

Copy link

coderabbitai bot commented Jul 16, 2025

Walkthrough

The changes introduce explicit ORM field-to-column mappings in several entity classes using @TableField annotations, update a controller method to manually deserialize JSON from the request, and adjust related tests. SQL mapping files are refactored for clarity and maintainability, and a database migration script is updated to omit a previously planned column addition.

Changes

File(s) Change Summary
app/src/main/resources/sql/mysql/update_all_tables_ddl.sql Removed addition of nullable app_id column from t_component_library table.
base/src/main/java/com/tinyengine/it/controller/PageController.java Changed createPage method to accept HttpServletRequest, manually deserialize JSON, updated annotations.
base/src/test/java/com/tinyengine/it/controller/PageControllerTest.java Updated test to use MockHttpServletRequest with JSON content for createPage.
base/src/main/java/com/tinyengine/it/model/entity/Component.java Added @TableField annotations to fields for explicit DB column mapping.
base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java Added @TableField annotations for DB columns; marked components field as non-persistent.
base/src/main/java/com/tinyengine/it/model/entity/PageHistory.java Added @TableField annotations for DB columns.
base/src/main/java/com/tinyengine/it/model/entity/Tenant.java Changed type of id from Integer to String.
base/src/main/resources/mappers/ComponentLibraryMapper.xml Refactored SQL: introduced reusable SELECT fragment, qualified columns, improved query maintainability.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PageController
    participant JsonUtils
    participant PageService

    Client->>PageController: POST /createPage (with JSON body)
    PageController->>JsonUtils: decode(request.getInputStream(), Page.class)
    JsonUtils-->>PageController: Page object
    PageController->>PageService: createPage(Page) or createFolder(Page) (based on isPage)
    PageService-->>PageController: Result<Page>
    PageController-->>Client: Result<Page>
Loading

Poem

A hop, a leap, a mapping neat,
Fields and columns now all meet.
The controller sniffs the JSON stream,
While tests and SQL join the team.
With every change, the code grows bright—
A rabbit’s work, both swift and light! 🐇

✨ 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: 4

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

117-117: Update Javadoc parameter documentation.

The parameter documentation still references "page" but the parameter is now "request".

-     * @param request the request
+     * @param request the HTTP request containing page data in JSON format
base/src/main/resources/mappers/ComponentLibraryMapper.xml (2)

17-84: Consider switching = to LIKE (or IN) for free-text columns.

For fields such as name, description, registry, framework, etc., an exact-match requirement is usually too strict from an API-consumer perspective. Unless the service contract mandates exact equality, replacing the equality operator with LIKE CONCAT('%', … ,'%') – or exposing an IN (…) clause for multi-selects – will make the search endpoints markedly more usable.

No code is wrong here, but re-evaluating the operator choice could avoid a follow-up PR.


289-293: Minor nit: <where> already strips a leading AND.

The guard <if test="id != null"> AND CL.id = #{id} </if> is fine, but the inner newline results in:

WHERE
    AND CL.id = ?

<where> removes the first AND, so the query still runs, but the redundant AND produces slightly uglier SQL in logs. Dropping it keeps the output clean:

-            AND CL.id = #{id}
+            CL.id = #{id}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ad25aba and 4c21648.

📒 Files selected for processing (8)
  • app/src/main/resources/sql/mysql/update_all_tables_ddl.sql (0 hunks)
  • base/src/main/java/com/tinyengine/it/controller/PageController.java (2 hunks)
  • base/src/main/java/com/tinyengine/it/model/entity/Component.java (4 hunks)
  • base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java (2 hunks)
  • base/src/main/java/com/tinyengine/it/model/entity/PageHistory.java (2 hunks)
  • base/src/main/java/com/tinyengine/it/model/entity/Tenant.java (1 hunks)
  • base/src/main/resources/mappers/ComponentLibraryMapper.xml (3 hunks)
  • base/src/test/java/com/tinyengine/it/controller/PageControllerTest.java (1 hunks)
💤 Files with no reviewable changes (1)
  • app/src/main/resources/sql/mysql/update_all_tables_ddl.sql
🧰 Additional context used
🧬 Code Graph Analysis (1)
base/src/main/java/com/tinyengine/it/controller/PageController.java (1)
base/src/main/java/com/tinyengine/it/common/utils/JsonUtils.java (1)
  • JsonUtils (45-349)
🔇 Additional comments (13)
base/src/test/java/com/tinyengine/it/controller/PageControllerTest.java (1)

74-80: Test correctly updated to match controller method signature change.

The test properly creates a MockHttpServletRequest with JSON content and appropriate content type, aligning with the controller's new manual JSON deserialization approach.

base/src/main/java/com/tinyengine/it/model/entity/PageHistory.java (3)

55-55: Good explicit column mapping for foreign key reference.

The @TableField(value = "ref_id") annotation clearly maps the page field to the ref_id column, improving ORM mapping clarity.


62-62: Appropriate foreign key column mapping.

The @TableField(value = "app_id") annotation correctly maps the app field to the app_id database column.


79-79: Correct handling of SQL reserved keyword.

The @TableField(value = "group") annotation properly escapes the group column name with backticks since group is a reserved SQL keyword.

base/src/main/java/com/tinyengine/it/model/entity/Component.java (3)

50-50: Clear field-to-column mapping for component name.

The @TableField(value = "name_en") annotation explicitly maps the component field to the name_en database column, improving code clarity.


79-79: Proper SQL keyword escaping.

The @TableField(value = "group") annotation correctly handles the SQL reserved keyword group with backtick escaping.


103-103: Consistent explicit column mappings.

The @TableField annotations for publicStatus, framework, and isTinyReserved provide clear mappings to their respective database columns (public, framework, tiny_reserved), improving ORM transparency.

Also applies to: 107-107, 117-117

base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java (4)

48-48: Clear foreign key mapping.

The @TableField(value = "app_id") annotation explicitly maps the appId field to the app_id database column.


53-53: Appropriate SQL keyword handling.

The @TableField(value = "package") annotation correctly maps packageName to the package column, handling the SQL reserved keyword appropriately.


87-87: Consistent boolean field mappings.

The @TableField annotations for publicStatus, isStarted, isOfficial, and isDefault provide clear mappings to their database columns with appropriate naming conventions.

Also applies to: 91-91, 95-95, 99-99


103-103: Correct non-persistent field annotation.

The @TableField(exist = false) annotation properly marks the components field as non-persistent, indicating it's a relationship field not stored directly in this table.

base/src/main/resources/mappers/ComponentLibraryMapper.xml (2)

221-281: Potential row explosion due to LEFT JOIN without de-duplication.

queryAllComponentLibrary and the other two queries now return one row per component because of
LEFT JOIN t_component C ON CL.id = C.library_id.

With a <collection> result mapping this is technically correct, but callers expecting a 1-row-per-library result (e.g. for pagination) will receive inflated counts. If the Java side paginates, the join should move to a second query or you should use DISTINCT CL.id … / windowing to keep the outer rowset unique.

Just a heads-up in case API behaviour changes unnoticed.


186-186: Good catch on the stray space in <collection>; mapping looks solid.

@lu-yg lu-yg merged commit abcd445 into opentiny:develop Jul 16, 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