Skip to content

[TASK-SIM-004] feat: add visit date conflict validation#2367

Open
BenjaminWong1205 wants to merge 2 commits intospring-projects:mainfrom
BenjaminWong1205:feature/TASK-SIM-004-prevent-visit-conflict
Open

[TASK-SIM-004] feat: add visit date conflict validation#2367
BenjaminWong1205 wants to merge 2 commits intospring-projects:mainfrom
BenjaminWong1205:feature/TASK-SIM-004-prevent-visit-conflict

Conversation

@BenjaminWong1205
Copy link
Copy Markdown

[TASK-SIM-004] feat: add visit date conflict validation

Summary

Prevent duplicate visit bookings for the same pet on the same date.

Changes

  • ✅ Added @UniqueConstraint(columnNames = {"pet_id", "visit_date"}) to Visit entity
  • ✅ Added in-memory conflict check in VisitController.processNewVisitForm
  • ✅ Updated H2 / MySQL / PostgreSQL schema scripts with unique index
  • ✅ Added 2 test cases: duplicate date (rejected) & different date (accepted)

Test Results

  • ✅ All tests passed
  • ✅ Coverage: VisitController ≥85%
  • ✅ Spring Java Format check passed

Validation Layers

Layer Mechanism Fallback
Database Unique index on (pet_id, visit_date) Prevents concurrent inserts
Java result.rejectValue() + in-memory check User-friendly error message
Frontend Thymeleaf field error rendering Highlights duplicate date

Checklist

  • Code compiles without errors
  • All unit tests pass
  • Code coverage ≥ 85%
  • Multi-database schema updated (H2/MySQL/PostgreSQL)
  • Code follows project conventions

- Add @UniqueConstraint(pet_id, visit_date) to Visit entity

- Add duplicate date check in VisitController

- Add 2 test cases (conflict / success)

- Update schema scripts for H2/MySQL/PostgreSQL

- Coverage: VisitController >= 85%

Closes TASK-SIM-004
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