Skip to content

45 add attachment dto - #104

Merged
johanbriger merged 5 commits into
mainfrom
45-add-attachment-dto
Apr 2, 2026
Merged

45 add attachment dto#104
johanbriger merged 5 commits into
mainfrom
45-add-attachment-dto

Conversation

@johanbriger

@johanbriger johanbriger commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

closes #45

Changes:

DTOs: Created AttachmentRequestDTO (for uploads) and AttachmentResponseDTO (for API responses).

AttachmentRequestDTO now includes a description field to allow users to label their uploads (e.g., "X-ray of left paw").

Entity: Added the description field to the Attachment entity.

Database: Updated schema.sql to include the description column in the attachment table

@johanbriger johanbriger linked an issue Apr 2, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new AttachmentRequest DTO and AttachmentResponse DTO are introduced to handle attachment operations. The Attachment entity is extended with a description field, and the corresponding database schema is updated with a description column.

Changes

Cohort / File(s) Summary
Attachment DTOs
src/main/java/org/example/vet1177/dto/request/attachment/AttachmentRequest.java, src/main/java/org/example/vet1177/dto/response/attachment/AttachmentResponse.java
New request and response records for attachment operations. AttachmentRequest validates recordId (UUID, @NotNull) and description (String, @NotBlank, max 500 chars). AttachmentResponse includes metadata fields for id, recordId, fileName, description, fileType, fileSizeBytes, uploadedAt, uploadedBy, and downloadUrl.
Attachment Entity & Schema
src/main/java/org/example/vet1177/entities/Attachment.java, src/main/resources/schema.sql
Extended Attachment entity with description field (String) mapped to description column via JPA annotations. Added corresponding nullable VARCHAR(500) column to database schema.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #29 – Introduced the initial Attachment entity and schema that this PR extends by adding description field and corresponding DTOs.
  • PR #32 – Added Jakarta Bean Validation dependency that this PR relies on for @NotNull, @NotBlank, and @Size annotations.

Suggested labels

enhancement

Suggested reviewers

  • lindaeskilsson

Poem

🐰 A description blooms, attached with care,
DTOs and validations float through the air,
Schema and entity dance hand in hand,
Details now captured, as planned!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title '45 add attachment dto' is partially related to the changeset. It mentions 'attachment dto' which accurately describes part of the changes (two new DTOs were added), but the title is vague and uses abbreviations like '45' and 'dto' without context. The title doesn't convey that it also adds an entity field and database schema change, and the generic phrasing makes it less descriptive than ideal. Consider revising the title to be more specific and descriptive, such as 'Add AttachmentRequest and AttachmentResponse DTOs with description field' to better represent all components of the change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 45-add-attachment-dto

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/resources/schema.sql (1)

70-81: ⚠️ Potential issue | 🟠 Major

Add an explicit migration path for existing databases.

The attachment table uses CREATE TABLE IF NOT EXISTS at line 70, which means the new description column added at line 75 will only be created for fresh deployments. On production systems with pre-existing attachment tables, the column won't be added, causing runtime failures when the JPA entity (which includes the description field) attempts to read or write to it.

Since the project has no migration framework and relies solely on schema.sql initialization, an explicit ALTER TABLE statement is needed to backfill the column on existing databases.

Suggested fix
 CREATE TABLE IF NOT EXISTS attachment (
   id              UUID        PRIMARY KEY DEFAULT gen_random_uuid(),
   record_id       UUID        NOT NULL REFERENCES medical_record(id) ON DELETE CASCADE,
   uploaded_by     UUID        REFERENCES users(id) ON DELETE SET NULL,
   file_name       VARCHAR(500) NOT NULL,
   description     VARCHAR(500),
   s3_key          VARCHAR(1000) NOT NULL UNIQUE,
   s3_bucket       VARCHAR(255) NOT NULL,
   file_type       VARCHAR(100),
   file_size_bytes BIGINT,
   uploaded_at     TIMESTAMPTZ NOT NULL DEFAULT NOW()
 );
+
+ALTER TABLE attachment
+    ADD COLUMN IF NOT EXISTS description VARCHAR(500);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/schema.sql` around lines 70 - 81, The schema uses CREATE
TABLE IF NOT EXISTS for the attachment table so adding the new description
column won't affect existing DBs; add an explicit migration ALTER TABLE
statement to add the description column to existing attachment rows (e.g., ALTER
TABLE attachment ADD COLUMN IF NOT EXISTS description VARCHAR(500);) so the JPA
entity's description field exists on pre-existing databases—target the
attachment table and the description column to ensure backward compatibility.
🧹 Nitpick comments (1)
src/main/java/org/example/vet1177/dto/request/attachment/AttachmentRequest.java (1)

13-15: Align requiredness across API and persistence for description.

Line 13 makes description mandatory at API level, while the entity/schema currently allow null. Consider enforcing the same invariant in persistence (nullable = false / NOT NULL) or relaxing request validation if optional is intended.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/example/vet1177/dto/request/attachment/AttachmentRequest.java`
around lines 13 - 15, AttachmentRequest declares description as required
(`@NotBlank`) but the persistence/schema allow null; pick one invariant and align
both: if description must be required, update the persistence model (the entity
field for description, e.g., AttachmentEntity.description or equivalent) to
`@Column`(nullable = false) and add a DB migration to set the column NOT NULL; if
description should be optional, relax the DTO by removing `@NotBlank` (or replace
with `@Nullable` and keep `@Size`(max=500) if desired) and adjust any callers/tests.
Ensure the same max length is enforced in the entity mapping (e.g., length=500)
and update tests/migrations accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/main/resources/schema.sql`:
- Around line 70-81: The schema uses CREATE TABLE IF NOT EXISTS for the
attachment table so adding the new description column won't affect existing DBs;
add an explicit migration ALTER TABLE statement to add the description column to
existing attachment rows (e.g., ALTER TABLE attachment ADD COLUMN IF NOT EXISTS
description VARCHAR(500);) so the JPA entity's description field exists on
pre-existing databases—target the attachment table and the description column to
ensure backward compatibility.

---

Nitpick comments:
In
`@src/main/java/org/example/vet1177/dto/request/attachment/AttachmentRequest.java`:
- Around line 13-15: AttachmentRequest declares description as required
(`@NotBlank`) but the persistence/schema allow null; pick one invariant and align
both: if description must be required, update the persistence model (the entity
field for description, e.g., AttachmentEntity.description or equivalent) to
`@Column`(nullable = false) and add a DB migration to set the column NOT NULL; if
description should be optional, relax the DTO by removing `@NotBlank` (or replace
with `@Nullable` and keep `@Size`(max=500) if desired) and adjust any callers/tests.
Ensure the same max length is enforced in the entity mapping (e.g., length=500)
and update tests/migrations accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7c1558e5-630a-4891-9ee7-ce9a4969e01d

📥 Commits

Reviewing files that changed from the base of the PR and between dae4e9a and 24dfdb8.

📒 Files selected for processing (4)
  • src/main/java/org/example/vet1177/dto/request/attachment/AttachmentRequest.java
  • src/main/java/org/example/vet1177/dto/response/attachment/AttachmentResponse.java
  • src/main/java/org/example/vet1177/entities/Attachment.java
  • src/main/resources/schema.sql

@annikaholmqvist94 annikaholmqvist94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snyggt med DTOs och annotationerna!! Bara lite tankar som vanligt :P haha

@NotNull(message = "Journal-ID får inte vara tomt")
UUID recordId,

@NotBlank(message = "Beskrivning av bilagan krävs")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

så om bilagan krävs, ska vi då sätta även NOT NULL I schemat och se till att @column i entiteten är nullable=false. Så vi säkrar upp att det finns värden?

@johanbriger johanbriger Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tagit bort not null då beskrivning bör vara valfritt

String fileType,
Long fileSizeBytes,
Instant uploadedAt,
String uploadedBy,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hur kommer det bli om detta är en String och i databasen har vi UUID? hmm..

@johanbriger johanbriger Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snyggt fångat! Vi vill ju inte skicka en UUID till frontend. Genom att ha det som en String i DTO:n kan vi mappa om UUID:t till personens riktiga namn innan vi skickar iväg svaret. Fixar det i servicen när den är klar!

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.

Add Attachment DTO

2 participants