Repository navigation
[Feat/#108] 습관 등록 알림 문구 수정 및 부모->자녀 알림 신규 추가 - #109
Conversation
📝 WalkthroughWalkthroughThe Changes
Sequence DiagramsequenceDiagram
actor User
participant HabitService
participant TransactionSync as TransactionSynchronizationManager
participant NotificationService
participant RecipientIDs
User->>HabitService: createHabit(request)
HabitService->>HabitService: persist habit
HabitService->>TransactionSync: register afterCommit callback
alt actor = CHILD
TransactionSync->>NotificationService: sendNotification(to=parentIDs, body="{childNick}(이)가 새 습관을 추가했어요...")
NotificationService->>RecipientIDs: deliver to parent IDs
else actor = PARENT
TransactionSync->>NotificationService: sendNotification(to=childIDs, body="{parentNick}님이 새 습관을 추가했어요...")
NotificationService->>RecipientIDs: deliver to child IDs
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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: 1
🧹 Nitpick comments (1)
src/main/java/com/swyp/server/domain/habit/service/HabitService.java (1)
61-103: Consider extracting duplicated role-based notification flow into a helper.Recipient lookup +
afterCommitregistration is duplicated across CHILD/PARENT branches. A small helper (role, recipients, message) will reduce drift in this P0 path.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/com/swyp/server/domain/habit/service/HabitService.java` around lines 61 - 103, HabitService contains duplicated logic for role-based notifications (two branches checking UserType.CHILD and UserType.PARENT) that repeats recipient lookup via familyRelationService.getConnectedMembers(userId) and TransactionSynchronizationManager.registerSynchronization with notificationService.sendToUsers; extract this into a private helper (e.g., notifyConnectedUsersByRole or scheduleRoleNotification) that accepts the source UserType, target UserType, and message template (or computed nickname+message), performs the filtered recipient id collection (.filter(m -> m.getUserType() == ...).map(User::getId).toList()), checks empty, and registers the afterCommit synchronization to call notificationService.sendToUsers; then replace both CHILD and PARENT branches to call that helper using user.getNickname() and the appropriate message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/main/java/com/swyp/server/domain/habit/service/HabitService.java`:
- Around line 68-69: The code currently uses user.getNickname() directly into
childNickname which can be null/blank and produce malformed push text; sanitize
and normalize the nickname before composing push bodies by replacing occurrences
of childNickname = user.getNickname() with a safe value (e.g., safeNickname =
(user.getNickname()!=null && !user.getNickname().isBlank()) ?
user.getNickname().trim() : ""); then use safeNickname wherever the push body is
composed (the same spots around
TransactionSynchronizationManager.registerSynchronization and the block around
lines 90-99) so notifications never include "null" or stray spacing.
---
Nitpick comments:
In `@src/main/java/com/swyp/server/domain/habit/service/HabitService.java`:
- Around line 61-103: HabitService contains duplicated logic for role-based
notifications (two branches checking UserType.CHILD and UserType.PARENT) that
repeats recipient lookup via familyRelationService.getConnectedMembers(userId)
and TransactionSynchronizationManager.registerSynchronization with
notificationService.sendToUsers; extract this into a private helper (e.g.,
notifyConnectedUsersByRole or scheduleRoleNotification) that accepts the source
UserType, target UserType, and message template (or computed nickname+message),
performs the filtered recipient id collection (.filter(m -> m.getUserType() ==
...).map(User::getId).toList()), checks empty, and registers the afterCommit
synchronization to call notificationService.sendToUsers; then replace both CHILD
and PARENT branches to call that helper using user.getNickname() and the
appropriate message.
🪄 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: b8cc61c4-45f4-4f4d-8a89-37c617b73a3c
📒 Files selected for processing (1)
src/main/java/com/swyp/server/domain/habit/service/HabitService.java
| String childNickname = user.getNickname(); | ||
| TransactionSynchronizationManager.registerSynchronization( |
There was a problem hiding this comment.
Handle null/blank nickname before composing push body.
user.getNickname() can be null/blank, so this can emit broken text like null(이)가... or 님이... in production notifications.
💡 Proposed fix
+ private String resolveNickname(String nickname, String fallback) {
+ return (nickname == null || nickname.isBlank()) ? fallback : nickname;
+ }
...
- String childNickname = user.getNickname();
+ String childNickname = resolveNickname(user.getNickname(), "자녀");
...
- childNickname + "(이)가 새 습관을 추가했어요. 보상을 확인해 볼까요?",
+ childNickname + "(이)가 새 습관을 추가했어요. 보상을 확인해 볼까요?",
...
- String parentNickname = user.getNickname();
+ String parentNickname = resolveNickname(user.getNickname(), "부모");
...
- parentNickname + "님이 새 습관을 추가했어요. 함께 힘내볼까요?",
+ parentNickname + "님이 새 습관을 추가했어요. 함께 힘내볼까요?",Also applies to: 90-99
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/main/java/com/swyp/server/domain/habit/service/HabitService.java` around
lines 68 - 69, The code currently uses user.getNickname() directly into
childNickname which can be null/blank and produce malformed push text; sanitize
and normalize the nickname before composing push bodies by replacing occurrences
of childNickname = user.getNickname() with a safe value (e.g., safeNickname =
(user.getNickname()!=null && !user.getNickname().isBlank()) ?
user.getNickname().trim() : ""); then use safeNickname wherever the push body is
composed (the same spots around
TransactionSynchronizationManager.registerSynchronization and the block around
lines 90-99) so notifications never include "null" or stray spacing.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/main/java/com/swyp/server/domain/habit/service/HabitService.java (1)
68-68:⚠️ Potential issue | 🟠 MajorHandle blank nicknames as well as nulls before composing push text.
Line 68 and Line 90 only guard
null. Blank/whitespace nicknames can still produce broken bodies (e.g.,님이 ..., leading spaces). Normalize withtrim()+isBlank()fallback before building the message.💡 Proposed fix
- String childNickname = user.getNickname() != null ? user.getNickname() : "자녀"; + String childNickname = resolveNickname(user.getNickname(), "자녀"); ... - String parentNickname = user.getNickname() != null ? user.getNickname() : "부모"; + String parentNickname = resolveNickname(user.getNickname(), "부모");private String resolveNickname(String nickname, String fallback) { return (nickname == null || nickname.isBlank()) ? fallback : nickname.trim(); }Also applies to: 90-90
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/com/swyp/server/domain/habit/service/HabitService.java` at line 68, The nickname handling in HabitService (where childNickname is assigned from user.getNickname() and the similar usage at line 90) only checks for null and fails to normalize blank/whitespace values; add a helper like resolveNickname(String nickname, String fallback) that returns fallback when nickname is null or isBlank(), otherwise returns nickname.trim(), and replace the direct user.getNickname() checks with calls to resolveNickname to ensure push text is composed without empty or leading-space nicknames.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/main/java/com/swyp/server/domain/habit/service/HabitService.java`:
- Line 68: The nickname handling in HabitService (where childNickname is
assigned from user.getNickname() and the similar usage at line 90) only checks
for null and fails to normalize blank/whitespace values; add a helper like
resolveNickname(String nickname, String fallback) that returns fallback when
nickname is null or isBlank(), otherwise returns nickname.trim(), and replace
the direct user.getNickname() checks with calls to resolveNickname to ensure
push text is composed without empty or leading-space nicknames.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3e06b538-8371-40d7-b1c0-bf9f0a029cd1
📒 Files selected for processing (1)
src/main/java/com/swyp/server/domain/habit/service/HabitService.java
📌 관련 이슈
✨ 변경 사항
📚 리뷰어 참고 사항
✅ 체크리스트
Summary by CodeRabbit