refactor: 알림 서비스 책임 분리 - #133
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthrough알림 모듈의 상수, 정책, 응답 매퍼, 저장소 헬퍼를 분리했습니다. 알림 서비스와 SSE 서비스는 분리된 모듈을 사용하도록 변경했습니다. Changes알림 처리 구조 정리
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
Service에 있던 정책 판단과 응답 매핑이 분리돼서 알림 처리 흐름이 훨씬 보기 좋아진 것 같습니다! |
📌 작업 내용
notification서비스에 혼재되어 있던 정책 판단, 응답 매핑, SSE 관련 상수 책임을 분리했습니다.policy로 분리했습니다.mapper로 분리했습니다.constants로 분리했습니다.create/createManydata 조립 중복을 정리했습니다.✅ 변경 사항
notification.constants.ts추가알림 도메인에서 사용하는 정책 및 SSE 관련 상수를 분리했습니다.
BULK_NOTIFICATION_BATCH_SIZECHAT_READ_VISIBILITY_DAYSNOTIFICATION_RETENTION_DAYSHEARTBEAT_INTERVAL_MSSUPPORTED_NOTICE_AUDIENCESNOTIFICATION_SSE_EVENTSnotification.policy.ts추가DB/Repository 의존 없이 입력값만으로 판단하거나 계산하는 순수 정책을 분리했습니다.
assertSupportedNoticeAudiencenormalizeBulkNotificationSourceIdassertValidBulkNotificationSnapshotAtassertReadableNotificationresolveReadExpiresAtresolveReadAllChatExpiresAtresolveCleanupDeleteBeforenotification.mapper.ts추가Service에서 처리하던 API Response 조립 책임을 분리했습니다.
mapNotificationListResponsemapUnreadNotificationCountResponsemapReadNotificationResponsemapReadAllNotificationsResponsemapOwnedNotificationToItemnotification.service.ts정리Service에는 다음 책임을 유지했습니다.
readAllNotifications()TransactioncreateNotification()DB 저장 경계sendNotification()SSE 전송 위임순수 정책 판단 및 Response 조립 로직은 각각
policy,mapper로 이동했습니다.notification.repository.ts정리다음 공통 로직을 분리해 중복을 줄였습니다.
notificationSelectownedNotificationSelectbuildActiveNotificationWheretoNotificationCreateDataPagination의
findMany + count구조는 기존대로 유지했습니다.notification-sse.service.ts정리SSE Connection Lifecycle은 기존 구조를 그대로 유지했습니다.
Heartbeat Interval 및 Event Name만
constants를 참조하도록 변경했습니다.🔄 Transaction / SSE 경계
기존 DB Transaction과 외부 I/O 경계를 유지했습니다.
createNotification()→ DB 저장만 담당sendNotification()→ SSE 전송만 담당sendNotificationRefresh()→ SSE Refresh Event 전송만 담당readAllNotifications()기존 Transaction 구조를 유지했습니다.
두 작업은 동일한 Transaction 내에서 수행되며 중간 실패 시 부분 반영되지 않도록 기존 원자성을 유지했습니다.
📢 Bulk Notification
기존 Bulk 알림 생성 동작을 유지했습니다.
createMany()유지BULK_NOTIFICATION_BATCH_SIZE = 500유지skipDuplicates유지sourceId기반 중복 방지 의미 유지sendNotificationRefresh()호출sourceId.trim()은 반복 호출하지 않고 Policy에서 한 번 정규화한 뒤 재사용하도록 정리했습니다.⏰ Read / Expiration
기존 알림 만료 정책을 유지했습니다.
3일동안 유지CHAT_READ_VISIBILITY_DAYS = 3적용expiresAt유지90일유지🧹 Cleanup
기존
notification-cleanup.job.tsScheduler를 유지했습니다.03:00실행90일유지🔢 Prisma Count 점검
추가적인
count()/_count변경은 진행하지 않았습니다.countUnreadByUserId()→ 기존count()사용 유지findMany + count유지_count로 전환할 명확한 Relation Count 구간 없음🔗 외부 모듈 영향 확인
다음 Notification 호출처를 확인했습니다.
estimate-requestestimate/customerestimate/moverreviewinquiryadmin/contentsadmin/noticejobs다음 Public Method Signature는 변경하지 않았습니다.
createNotificationcreateBulkNotificationsendNotificationcleanupExpiredNotifications따라서 기존 호출처 수정은 발생하지 않았습니다.
🛡️ API Contract
기존 Contract를 유지했습니다.
title / content / linkUrl / expiresAt변경 없음🧪 테스트
실행
npm run lint npm run build npm test결과
lint: PASSbuild: PASStest: PASS74 passed, 0 failed테스트 로그의 Rate Limit 관련 Error 출력은 기존 기대 로그이며 테스트 실패는 아닙니다.
📷 스크린샷
백엔드 구조 리팩토링으로 UI 변경 사항은 없습니다.
🔥 체크리스트
console.log를 제거했습니다.🙏 To Reviewer
기능 변경이 아닌 Notification 모듈의 책임 분리를 목적으로 진행한 리팩토링입니다.
Service에는 Use Case Orchestration, Repository 호출 순서, Transaction 및 SSE 전송 시점 결정을 유지했습니다.
DB 접근이 필요 없는 읽기/만료/Bulk/Cleanup 관련 순수 로직은
policy로, API Response 조립은mapper로 분리했습니다.SSE Connection Lifecycle은 기존
notification-sse.service.ts에 그대로 유지하고 Event Name / Heartbeat 값만 Constants로 정리했습니다.특히 아래 부분이 기존과 동일하게 유지되는지 중점적으로 확인 부탁드립니다.
createNotification()의 DB 저장 책임sendNotification()의 SSE 전송 책임readAllNotifications()의 TransactionsourceId + skipDuplicates중복 방지후속 개선 후보
createNotification(..., tx)와 Commit 이후sendNotification()호출 경계 일관성 재점검Summary by CodeRabbit