AFFiNE icon indicating copy to clipboard operation
AFFiNE copied to clipboard

feat(server): comment model

Open fengmk2 opened this issue 7 months ago • 3 comments

close CLOUD-226

PR Dependency Tree

  • PR #12760 👈
    • PR #12761
      • PR #12795

This tree was auto-generated by Charcoal

fengmk2 avatar Jun 09 '25 05:06 fengmk2

"""

Walkthrough

This change introduces a comprehensive comment and reply system to the backend, including database migrations, Prisma schema updates, model implementation, error handling, and localization. It adds new models, error types, and test coverage, and integrates the comment model into the backend infrastructure, supporting comment and reply operations with full lifecycle management and change tracking.

Changes

Files / Grouped Files Change Summary
packages/backend/server/migrations/20250609050058_add_comment/migration.sql Adds comments and replies tables with indexes and foreign keys for comment/reply storage.
packages/backend/server/schema.prisma Adds Comment and Reply models, updates User and Workspace relations, and adds relevant indexes.
packages/backend/server/src/models/comment.ts Implements CommentModel class for comment/reply CRUD, validation, and change tracking.
packages/backend/server/src/models/__tests__/comment.spec.ts, .../__tests__/__snapshots__/comment.spec.ts.md Adds comprehensive tests and snapshots for comment/reply model functionality.
packages/backend/server/src/models/index.ts Integrates CommentModel into models system and exports it.
packages/backend/server/src/base/error/def.ts Adds user-friendly errors: comment_not_found, reply_not_found.
packages/backend/server/src/base/error/errors.gen.ts Adds error classes and enum entries for CommentNotFound, ReplyNotFound.
packages/backend/server/src/schema.gql Adds COMMENT_NOT_FOUND, REPLY_NOT_FOUND to ErrorNames enum.
packages/common/graphql/src/schema.ts Adds COMMENT_NOT_FOUND, REPLY_NOT_FOUND to ErrorNames enum.
packages/frontend/i18n/src/i18n.gen.ts, .../resources/en.json Adds i18n keys/messages for COMMENT_NOT_FOUND, REPLY_NOT_FOUND.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommentModel
    participant PrismaDB

    User->>CommentModel: createComment(input)
    CommentModel->>PrismaDB: insert Comment
    PrismaDB-->>CommentModel: created Comment
    CommentModel-->>User: Comment

    User->>CommentModel: createReply(input)
    CommentModel->>PrismaDB: check Comment exists
    alt Comment not found
        CommentModel-->>User: throw CommentNotFound
    else Comment exists
        CommentModel->>PrismaDB: insert Reply
        PrismaDB-->>CommentModel: created Reply
        CommentModel-->>User: Reply
    end

    User->>CommentModel: list(workspaceId, docId)
    CommentModel->>PrismaDB: fetch Comments + Replies
    PrismaDB-->>CommentModel: Comments with Replies
    CommentModel-->>User: CommentWithReplies[]

Assessment against linked issues

Objective (Issue) Addressed Explanation
Implement comment model with CRUD for comments and replies (CLOUD-226)
Add error handling for comment/reply not found (CLOUD-226)
Integrate comment model into backend models system (CLOUD-226)
Add tests for comment/reply model operations (CLOUD-226)

Poem

In the garden of code where new features sprout,
Comments and replies now hop all about!
With errors well-handled and models robust,
The backend’s grown stronger, in code we trust.
Snapshots and schemas, all neat in a row—
A rabbit’s delight as new functions grow!
🐇✨ """

✨ 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.

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.

coderabbitai[bot] avatar Jun 09 '25 05:06 coderabbitai[bot]


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

fengmk2 avatar Jun 09 '25 05:06 fengmk2

Codecov Report

Attention: Patch coverage is 99.44134% with 2 lines in your changes missing coverage. Please review.

Project coverage is 56.29%. Comparing base (9b881eb) to head (80aa0fa). Report is 1 commits behind head on canary.

Files with missing lines Patch % Lines
...ckages/backend/server/src/base/error/errors.gen.ts 86.66% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #12760      +/-   ##
==========================================
- Coverage   56.60%   56.29%   -0.32%     
==========================================
  Files        2670     2671       +1     
  Lines      127868   128225     +357     
  Branches    20224    20161      -63     
==========================================
- Hits        72380    72184     -196     
- Misses      53309    53875     +566     
+ Partials     2179     2166      -13     
Flag Coverage Δ
server-test 78.96% <99.44%> (-0.87%) :arrow_down:
unittest 31.90% <ø> (+<0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 09 '25 05:06 codecov[bot]