Skip to content

[Feat/#108] 습관 등록 알림 문구 수정 및 부모->자녀 알림 신규 추가 - #109

Merged
yunmi-dev merged 2 commits into
developfrom
feat/#108-habit-notification
Apr 7, 2026
Merged

yunmi-dev merged 2 commits into
developfrom
feat/#108-habit-notification

Conversation

@yunmi-dev

@yunmi-dev yunmi-dev commented Apr 6, 2026 •

Copy link
Copy Markdown
Collaborator

📌 관련 이슈

✨ 변경 사항

  • 자녀 습관 등록 시 부모 알림 문구 변경
    • 기존: "새로운 보상이 추가됐어요! 지금 바로 수락해 볼까요?"
    • 변경: "{자녀닉네임}(이)가 새 습관을 추가했어요. 보상을 확인해 볼까요?"
  • 부모 습관 등록 시 자녀 알림 추가
    • 추가: "{부모닉네임}님이 새 습관을 추가했어요. 함께 힘내볼까요?"

📚 리뷰어 참고 사항

  • createHabit에서만 수정했고, 기존 로직 변경 없음
  • 닉네임은 User.getNickname()에서 가져옴

✅ 체크리스트

  • 브랜치 전략(git flow)을 따랐나요?
  • 로컬에서 빌드 및 실행이 정상적으로 되나요?
  • 불필요한 주석이나 더미 코드는 제거했나요?
  • 컨벤션(커밋 메시지, 코드 스타일)을 지켰나요?
  • spotlessApply 실행했나요?

Summary by CodeRabbit

  • New Features
    • Habit creation notifications are now personalized and role-aware: when a child adds a habit, parents receive a notification with the child's nickname; when a parent adds a habit, connected children receive a notification with the parent's nickname.
    • Notification delivery is adjusted to ensure role-dependent recipients receive the appropriate dynamic message.

@coderabbitai

coderabbitai Bot commented Apr 6, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The createHabit flow now registers role-dependent post-commit notification callbacks: when a CHILD creates a habit, parents receive a message including the child's nickname; when a PARENT creates a habit, connected children receive a message including the parent's nickname.

Changes

Cohort / File(s) Summary
Habit Service Notification Logic
src/main/java/com/swyp/server/domain/habit/service/HabitService.java
Adjusted createHabit post-commit notifications to branch on actor UserType. CHILD branch: send parent notifications with child nickname. PARENT branch: gather connected child IDs and send child notifications with parent nickname. Registered separate afterCommit callbacks for each role.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • SeHyeonCho
  • guzzang

Poem

🐰 I hopped by code and left a trace,

Nicknames dancing in the notification space,
Parent to child and child to kin,
New habits start with a cheerful din,
Thump-thump—messages delivered with grace!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ 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 clearly and specifically describes the main changes: modifying habit registration notification messages and adding new parent-to-child notifications, directly matching the changeset content.
Linked Issues check ✅ Passed The code changes fully implement both requirements from issue #108: modified child-to-parent notification with child nickname, and added parent-to-child notification with parent nickname.
Out of Scope Changes check ✅ Passed All changes are contained to the createHabit method and directly address the notification behavior modifications specified in issue #108 without introducing unrelated changes.

✏️ 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 feat/#108-habit-notification

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.

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 + afterCommit registration 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

📥 Commits

Reviewing files that changed from the base of the PR and between e28a165 and 11d6581.

📒 Files selected for processing (1)
  • src/main/java/com/swyp/server/domain/habit/service/HabitService.java

Comment on lines 68 to 69
String childNickname = user.getNickname();
TransactionSynchronizationManager.registerSynchronization(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

@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.

♻️ Duplicate comments (1)
src/main/java/com/swyp/server/domain/habit/service/HabitService.java (1)

68-68: ⚠️ Potential issue | 🟠 Major

Handle 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 with trim() + 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

📥 Commits

Reviewing files that changed from the base of the PR and between 11d6581 and 5c033b6.

📒 Files selected for processing (1)
  • src/main/java/com/swyp/server/domain/habit/service/HabitService.java

@guzzang guzzang 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.

고생하셨습니다!!

@yunmi-dev
yunmi-dev merged commit c76f2de into develop Apr 7, 2026
1 check passed
@yunmi-dev
yunmi-dev deleted the feat/#108-habit-notification branch April 7, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] 습관 등록 푸시알림 문구 변경 및 알림 신규 추가

2 participants