Skip to content

Add Comment DTOs and update Comment handling#40

Open
annikaholmqvist94 wants to merge 2 commits intomainfrom
feat/comment-dtos
Open

Add Comment DTOs and update Comment handling#40
annikaholmqvist94 wants to merge 2 commits intomainfrom
feat/comment-dtos

Conversation

@annikaholmqvist94
Copy link
Copy Markdown
Contributor

@annikaholmqvist94 annikaholmqvist94 commented Mar 29, 2026

  • Introduced CreateCommentRequest and UpdateCommentRequest DTOs with validation.
  • Added CommentResponse DTO for transformed comment views.
  • Updated CommentRepository with @EntityGraph for optimized fetching.
  • Removed cascade behavior from medicalRecord and author relationships in Comment entity.
  • Added jakarta.validation-api dependency to enable validation annotations.

Closes #25

Summary by CodeRabbit

  • New Features

    • Create and update comments with validation and automatic author/timestamp tracking
    • API now returns richer comment data including record and author details
  • Bug Fixes

    • Comments are no longer removed automatically when related records or users are deleted
  • Refactor

    • Improved comment retrieval performance for faster listing and display

- Introduced `CreateCommentRequest` and `UpdateCommentRequest` DTOs with validation.
- Added `CommentResponse` DTO for transformed comment views.
- Updated `CommentRepository` with `@EntityGraph` for optimized fetching.
- Removed cascade behavior from `medicalRecord` and `author` relationships in `Comment` entity.
- Added `jakarta.validation-api` dependency to enable validation annotations.

Closes #25
@annikaholmqvist94 annikaholmqvist94 added the enhancement New feature or request label Mar 29, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b65d55f0-6437-44d9-9571-5e7db1242c7b

📥 Commits

Reviewing files that changed from the base of the PR and between 5aefd9a and 1cf05db.

📒 Files selected for processing (1)
  • pom.xml
✅ Files skipped from review due to trivial changes (1)
  • pom.xml

📝 Walkthrough

Walkthrough

Added Spring Boot validation starter dependency; introduced comment request/response DTO records with Jakarta Bean Validation annotations; removed cascade delete on Comment entity relationships; and added EntityGraph annotations to Comment repository query methods.

Changes

Cohort / File(s) Summary
Maven Dependency
pom.xml
Added org.springframework.boot:spring-boot-starter-validation to enable Spring Boot validation support.
Comment Request DTOs
src/main/java/org/example/vet1177/dto/request/comment/CreateCommentRequest.java, src/main/java/org/example/vet1177/dto/request/comment/UpdateCommentRequest.java
Added CreateCommentRequest(UUID recordId, String body) and UpdateCommentRequest(String body) records with Jakarta Bean Validation annotations (@NotNull, @NotBlank, @Size) and Swedish messages.
Comment Response DTO
src/main/java/org/example/vet1177/dto/response/comment/CommentResponse.java
Added CommentResponse record with fields (id, recordId, authorId, authorName, body, createdAt, updatedAt) and a static from(Comment) factory mapping entity → DTO including nested relations.
Comment Entity
src/main/java/org/example/vet1177/entities/Comment.java
Removed cascade = CascadeType.REMOVE from @ManyToOne associations (medicalRecord, author); retained fetch = FetchType.LAZY.
Comment Repository
src/main/java/org/example/vet1177/repository/CommentRepository.java
Added @EntityGraph(attributePaths = {"medicalRecord", "author"}) to findByMedicalRecordIdOrderByCreatedAtAsc(UUID) and findByAuthorId(UUID) to load associated entities with queries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • Add Comment entity and CommentRepository #28 — Modifies Comment entity and repository in similar areas (cascade settings and repository methods), overlapping with this PR's changes to associations and query fetch strategy.

Suggested reviewers

  • johanbriger
  • lindaeskilsson
  • TatjanaTrajkovic

Poem

🐰 I hopped through code with careful paws,
DTOs in hand and validation laws,
No cascade leaps, relations stay neat,
Entity graphs fetch friends we meet,
A tiny change, but tidy and sweet.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: adding Comment DTOs (CreateCommentRequest, UpdateCommentRequest, CommentResponse) and updating Comment handling (repository EntityGraph, entity cascade removal).
Linked Issues check ✅ Passed The PR successfully implements the Comment DTO requirement from issue #25: CreateCommentRequest and UpdateCommentRequest with validation annotations, CommentResponse for responses, and supporting infrastructure updates.
Out of Scope Changes check ✅ Passed All changes directly support the Comment DTO implementation: validation framework update, repository optimization with EntityGraph, and cascade removal fix are all necessary infrastructure for proper DTO and entity handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/comment-dtos

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pom.xml`:
- Around line 76-81: Remove the explicit
jakarta.validation:jakarta.validation-api dependency and replace it with
org.springframework.boot:spring-boot-starter-validation so the project gets the
Jakarta Validation API, Hibernate Validator runtime, and Spring Boot validation
auto-configuration; update the pom by deleting the dependency block for
jakarta.validation-api and adding a dependency for
spring-boot-starter-validation
(org.springframework.boot:spring-boot-starter-validation) aligned with your
Spring Boot 4.0.4 BOM.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d71b4ad6-1e71-42ed-b191-e3ea35cdb41d

📥 Commits

Reviewing files that changed from the base of the PR and between f8bf8c0 and 5aefd9a.

📒 Files selected for processing (6)
  • pom.xml
  • src/main/java/org/example/vet1177/dto/request/comment/CreateCommentRequest.java
  • src/main/java/org/example/vet1177/dto/request/comment/UpdateCommentRequest.java
  • src/main/java/org/example/vet1177/dto/response/comment/CommentResponse.java
  • src/main/java/org/example/vet1177/entities/Comment.java
  • src/main/java/org/example/vet1177/repository/CommentRepository.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Comment DTO

1 participant