[Feat] 약물노트 조회/검색/수정/삭제 기능 구현 - #60
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
MedicationUpdateRequest, MedicationNoteGroupResponse, MedicationNoteItemResponse 추가 MedicationNoteItemResponse에 isActive 포함 — 프론트 재등록 버튼 노출 판단용 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
findAllBySeniorId — 활성/비활성 전체 조회 (isActive 조건 제거) searchByKeyword — 약 이름/별명/병원명 키워드 + 기간 필터 deleteAllByMedication_Id — 약 삭제 시 스케줄 일괄 제거용 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
update — null 필드 유지, timesPerDay 변경 시 스케줄 재생성, endDate 자동 재계산 delete — 스케줄 먼저 삭제 후 Medication 하드 삭제 (Figma 스펙 기준 복구 불가) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
getNoteList — 전체 약 startDate+병원 기준 그룹화 반환 searchNotes — 키워드 + 기간 필터(1w/1m/3m/1y) 검색 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
GET /api/medications/notes
GET /api/medications/notes/search
PATCH /api/medications/{medicationId}
DELETE /api/medications/{medicationId}
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 52 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthrough약물노트 목록/검색 조회, 약 정보 수정, 약 삭제 기능이 추가되었습니다. Changes약물노트 API 구현
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant MedicationController
participant MedicationQueryService
participant MedicationRepository
participant MedicationConverter
Client->>MedicationController: GET /api/medications/notes/search?keyword&period
MedicationController->>MedicationQueryService: searchNotes(userId, seniorId, keyword, period)
MedicationQueryService->>MedicationQueryService: resolveFromDate(period)
MedicationQueryService->>MedicationRepository: searchByKeyword(seniorId, keyword, fromDate)
MedicationRepository-->>MedicationQueryService: List<Medication>
MedicationQueryService->>MedicationConverter: toNoteItemResponse(각 Medication)
MedicationQueryService-->>MedicationController: List<MedicationNoteGroupResponse>
MedicationController-->>Client: ok(응답)
sequenceDiagram
participant Client
participant MedicationController
participant MedicationCommandService
participant MedicationRepository
participant MedicationScheduleRepository
Client->>MedicationController: DELETE /api/medications/{medicationId}
MedicationController->>MedicationCommandService: delete(userId, medicationId)
MedicationCommandService->>MedicationRepository: findById + 소유권 검증
MedicationCommandService->>MedicationScheduleRepository: deleteAllByMedication_Id(medicationId)
MedicationCommandService->>MedicationRepository: 약 엔티티 삭제
MedicationCommandService-->>MedicationController: void
MedicationController-->>Client: noContent
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/main/java/com/piuda/callcare/domain/medication/controller/MedicationController.java`:
- Around line 73-82: Add validation to the MedicationController update endpoint
by annotating the MedicationUpdateRequest parameter in update() with `@Valid`,
matching the existing registerBatch() pattern. This ensures Bean Validation on
non-null PATCH fields is applied before medicationCommandService.update(userId,
medicationId, request) runs, while keeping the controller’s request handling
consistent.
In
`@src/main/java/com/piuda/callcare/domain/medication/dto/request/MedicationUpdateRequest.java`:
- Around line 17-20: `MedicationUpdateRequest`의 `timesPerDay`와 `totalDays`는
null만 허용하고 0 같은 무효값은 막아야 합니다. 해당 DTO 필드에 최소값 검증 어노테이션(`@Min(1)` 또는 `@Positive`)을
추가해 `null`은 유지하되 1 미만 값이 통과하지 않도록 수정하세요. `timesPerDay`, `totalDays` 선언부를 중심으로
검토하고, 다른 update request DTO에도 동일한 패턴이 있는지 함께 확인하세요.
In
`@src/main/java/com/piuda/callcare/domain/medication/service/command/MedicationCommandService.java`:
- Around line 122-125: `MedicationCommandService`의 날짜 계산 로직에서
`request.startDate()`가 없을 때 `medication.getStartDate()`가 null이면
`effectiveStart.plusDays(...)`에서 NPE가 발생합니다. `updateMedication`(해당 계산 블록)에서
`effectiveStart`를 사용하기 전에 null 가드를 추가하고, `request.totalDays()`만 들어온 경우에도
`medication.getStartDate()`가 없으면 안전하게 처리하거나 명시적으로 예외를 반환하도록 수정하세요.
`effectiveStart`, `effectiveDays`, `newEndDate` 계산 순서를 점검해 null인 경우를 먼저 방어하면
됩니다.
In
`@src/main/java/com/piuda/callcare/domain/medication/service/query/MedicationQueryService.java`:
- Around line 80-88: `MedicationQueryService.resolveFromDate` is treating
`period` case-sensitively, so uppercase inputs like "1W" fall through to the
default path. Normalize the incoming `period` to lowercase before the switch
(while still handling null safely) so `1w`, `1m`, and `3m` are matched
consistently and only truly unknown values use the default branch.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 57228a13-0502-4c28-b147-6e190df374df
📒 Files selected for processing (10)
src/main/java/com/piuda/callcare/domain/medication/controller/MedicationController.javasrc/main/java/com/piuda/callcare/domain/medication/converter/MedicationConverter.javasrc/main/java/com/piuda/callcare/domain/medication/dto/request/MedicationUpdateRequest.javasrc/main/java/com/piuda/callcare/domain/medication/dto/response/MedicationNoteGroupResponse.javasrc/main/java/com/piuda/callcare/domain/medication/dto/response/MedicationNoteItemResponse.javasrc/main/java/com/piuda/callcare/domain/medication/entity/Medication.javasrc/main/java/com/piuda/callcare/domain/medication/repository/MedicationRepository.javasrc/main/java/com/piuda/callcare/domain/medication/repository/MedicationScheduleRepository.javasrc/main/java/com/piuda/callcare/domain/medication/service/command/MedicationCommandService.javasrc/main/java/com/piuda/callcare/domain/medication/service/query/MedicationQueryService.java
🔍️ 작업 내용
약물노트 조회/검색/수정/삭제 기능 구현
✨ 상세 설명
약물노트 목록 조회 —
GET /api/medications/notesstartDate+hospitalName기준으로 그룹화하여 반환isActive값으로 "복용중" 뱃지 / "약물 재등록" 버튼을 구분 노출할 수 있도록 함약물노트 검색 —
GET /api/medications/notes/searchperiod: 1w/1m/3m/1y, 기본값 1y)약 수정 —
PATCH /api/medications/{medicationId}startDate/totalDays변경 시endDate자동 재계산timesPerDay변경 시 기존 스케줄 삭제 후 재생성약 삭제 —
DELETE /api/medications/{medicationId}MedicationSchedule먼저 삭제 후Medication완전 삭제변경 파일
Medication엔티티 —update()메서드 추가MedicationUpdateRequest,MedicationNoteGroupResponse,MedicationNoteItemResponse— DTO 신규MedicationConverter—toNoteItemResponse추가MedicationRepository—findAllBySeniorId(활성/비활성 전체 조회),searchByKeyword수정(isActive 조건 제거)MedicationScheduleRepository— 스케줄 삭제 메서드 활용MedicationCommandService—update,delete추가MedicationQueryService—getNoteList,searchNotes추가MedicationController— 4개 엔드포인트 추가🛠️ 추후 리팩토링 및 고도화 계획
prescriptionDate) 파싱 기능 추가 시, 그룹화 기준을startDate→prescriptionDate ?? startDate로 전환 검토isActive = false처리하는 배치/스케줄러 로직 (현재deactivate()메서드는 준비만 되어 있고 호출부 없음)📸 스크린샷 (선택)
💬 리뷰 요구사항
findAllBySeniorId에서isActive필터를 뺀 것이 다른 기능(예: 리포트, 홈카드)에 영향 없는지 확인 필요Summary by CodeRabbit
새 기능
버그 수정