[fix] 신고 중복 문제 해결 - #136
Conversation
|
Caution Review failedThe pull request is closed. Walkthrough신고 처리에 사용자 단위 중복 제약을 추가하고, 저장 중 제약 위반을 예외로 처리하도록 변경했으며 애플리케이션 수준 비동기( Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client as 사용자
participant Controller as ReportController
participant Service as ReportService
participant Repo as ReportRepository
participant DB as Database
participant Mail as MailService (Async)
Client->>Controller: 신고 요청 (commentId, userId, ... )
Controller->>Service: reportTeamficialLog(...)
Service->>Repo: existsByReportedCommentIdAndUserId(commentId, userId)
Repo->>DB: SELECT EXISTS ...
DB-->>Repo: 존재 여부 반환
Repo-->>Service: exists? false
Service->>Repo: save(report)
Repo->>DB: INSERT report
DB-->>Repo: 성공 or ConstraintViolation
alt insert success
Service-->>Mail: sendReportEmail(toEmail) (비동기)
Mail-->>Service: (비동기 실행, 로그 처리 on error)
Service-->>Controller: 생성 완료 응답
Controller-->>Client: 201 Created
else constraint violation
Repo-->>Service: DataIntegrityViolationException
Service-->>Controller: throw GeneralException(REPORT_DUPLICATE)
Controller-->>Client: 409 Conflict (REPORT_DUPLICATE)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 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 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
🤖 Fix all issues with AI agents
In
`@src/main/java/teamficial/teamficial_be/domain/report/service/MailService.java`:
- Around line 31-33: The catch block in MailService currently logs raw PII
(toEmail); replace that with a non-PII identifier (e.g., userId) or a masked
email before logging: update the catch in the method in MailService to log
either the associated userId or call a new/existing maskEmail(toEmail) helper
and pass that masked value to log.error instead of toEmail, keeping the
exception e as the last parameter; ensure maskEmail produces a deterministic,
irreversible mask (like keeping first char and domain or replacing local-part
with asterisks).
🧹 Nitpick comments (3)
src/main/java/teamficial/teamficial_be/global/apiPayload/code/status/ErrorStatus.java (1)
59-61: 에러 코드 명명 규칙 불일치
REPORT_DUPLICATE의 에러 코드가"REPORT409"로 변경되었는데, 동일 파일 내 다른 에러 코드들(REPORT4002,REPORT404등)과 명명 패턴이 일치하지 않습니다. HTTP 상태 코드를 에러 코드 문자열에 직접 포함하는 것은 다른 코드들의 패턴과 다릅니다.일관성을 위해 기존 패턴(
REPORT4001)을 유지하거나, 전체 에러 코드 체계를 통일하는 것을 권장합니다.src/main/java/teamficial/teamficial_be/TeamficialBeApplication.java (1)
9-9: 비동기 처리를 위한 커스텀 Executor 설정 고려
@EnableAsync만 사용하면 기본SimpleAsyncTaskExecutor가 사용되며, 이는 요청마다 새 스레드를 생성합니다. 프로덕션 환경에서는 스레드 풀 크기, 큐 용량 등을 제어할 수 있는ThreadPoolTaskExecutor를 별도로 설정하는 것이 권장됩니다.현재 이메일 전송만 비동기로 처리하므로 즉시 필요하지는 않지만, 향후 비동기 작업이 늘어날 경우 고려해 주세요.
src/main/java/teamficial/teamficial_be/domain/report/service/ReportService.java (1)
53-57:DataIntegrityViolationException포괄적 캐치 주의
DataIntegrityViolationException을 포괄적으로 캐치하면, 유니크 제약 위반 외에 다른 무결성 제약 위반(예: 외래키 위반, NOT NULL 위반 등)도 모두REPORT_DUPLICATE로 처리될 수 있습니다.더 정확한 에러 처리를 위해 예외 메시지나 원인을 검사하여 실제 유니크 제약 위반인지 확인하는 것을 고려해 주세요.
♻️ 개선 제안
try { reportRepository.save(report); } catch (DataIntegrityViolationException e) { + if (e.getMessage() != null && e.getMessage().contains("user_id") && e.getMessage().contains("reported_comment_id")) { + throw new GeneralException(ErrorStatus.REPORT_DUPLICATE); + } + throw e; // 다른 무결성 위반은 그대로 전파 - throw new GeneralException(ErrorStatus.REPORT_DUPLICATE); }
#️⃣연관된 이슈
📝작업 내용
신고 버튼을 빠르게 여러번 클릭 시, db에 데이터가 누른 횟수만큼 저장되는 문제
-> Transactional과 alreadyExistReport 검사 사이에 Race Condition이 발생한 거 같아 유니크 제약 조건과 try-catch문 추가했습니다
신고 후 API 응답까지 시간이 오래 걸리는 문제
-> 이메일 전송까지 동기적으로 처리되어 오래 걸린 거 같습니다 이메일 전송은 Async처리 했습니다.
스크린샷
💬리뷰 요구사항(선택)
Summary by CodeRabbit
버그 수정
개선 사항