@@ -40,29 +40,51 @@ public SaveUrlResponse saveUrl(String email, String url) {
4040
4141 @ Transactional
4242 public ConfirmResponse confirm (String inviterEmail , Long accepterId ) {
43- // 초대자 조회(사용자: 여성)
44- User inviter = userRepository .findByEmail (inviterEmail ).orElseThrow (() -> new IllegalArgumentException ("초대자를 찾을 수 없습니다." ));
45-
46- // 수락자 조회 (파트너: 남성)
47- User accepter = userRepository .findById (accepterId ).orElseThrow (() -> new IllegalArgumentException ("수락자를 찾을 수 없습니다." ));
48-
49- // 공유 조회
50- Sharing sharing = sharingRepository .findByUser (inviter ).orElseThrow (() -> new IllegalStateException ("공유 정보가 존재하지 않습니다." ));
51-
43+ log .info ("[CONFIRM] 시작: inviterEmail={}, accepterId={}" , inviterEmail , accepterId );
44+
45+ // 1. 초대자 조회(사용자: 여성)
46+ User inviter = userRepository .findByEmail (inviterEmail )
47+ .orElseThrow (() -> {
48+ log .warn ("[CONFIRM] 초대자 없음: inviterEmail={}" , inviterEmail );
49+ return new IllegalArgumentException ("초대자를 찾을 수 없습니다." );
50+ });
51+ log .info ("[CONFIRM] 초대자 조회 성공: inviterId={}, email={}" , inviter .getUserId (), inviter .getEmail ());
52+
53+ // 2. 수락자 조회 (파트너: 남성)
54+ User accepter = userRepository .findById (accepterId )
55+ .orElseThrow (() -> {
56+ log .warn ("[CONFIRM] 수락자 없음: accepterId={}" , accepterId );
57+ return new IllegalArgumentException ("수락자를 찾을 수 없습니다." );
58+ });
59+ log .info ("[CONFIRM] 수락자 조회 성공: accepterId={}, email={}" , accepter .getUserId (), accepter .getEmail ());
60+
61+ // 3. 공유 조회
62+ Sharing sharing = sharingRepository .findByUser (inviter )
63+ .orElseThrow (() -> {
64+ log .warn ("[CONFIRM] 공유 정보 없음: inviterId={}" , inviter .getUserId ());
65+ return new IllegalStateException ("공유 정보가 존재하지 않습니다." );
66+ });
67+ log .info ("[CONFIRM] 공유 조회 성공" );
68+
69+ // 4. 이미 수락된 초대
5270 if (sharing .isConfirmed ()) {
71+ log .warn ("[CONFIRM] 이미 수락된 초대" );
5372 throw new IllegalStateException ("이미 수락된 초대입니다." );
5473 }
5574
56- // Couple 중복 생성 방지, 추후 메서드 분리 고려
75+ // 5. Couple 중복 생성 방지
5776 boolean coupleExists = coupleRepository .existsByUserOrPartnerUserId (inviter , accepter .getUserId ());
5877 if (coupleExists ) {
78+ log .warn ("[CONFIRM] 이미 커플 등록: inviterId={}, accepterId={}" , inviter .getUserId (), accepter .getUserId ());
5979 throw new IllegalStateException ("이미 커플로 등록된 사용자입니다." );
6080 }
6181
82+ log .info ("[CONFIRM] sharing.confirm() 실행" );
6283 sharing .confirm ();
6384 sharingRepository .save (sharing ); // 명시적 저장
6485
65- // 여기서 알림 서비스 호출
86+ // 6. 알림 서비스 호출
87+ log .info ("[CONFIRM] 알림 발송: fromUser={}, toUser={}" , accepter .getUserId (), inviter .getUserId ());
6688 notificationService .sendNotification (
6789 inviter .getUserId (), // 알림 받을 사람: 초대자(여성)
6890 accepter .getUserId (), // 알림 보낸 사람: 수락자(남성)
@@ -71,6 +93,8 @@ public ConfirmResponse confirm(String inviterEmail, Long accepterId) {
7193 accepter .getNickname () + "님이 파트너 요청을 수락했습니다!"
7294 );
7395
96+ log .info ("[CONFIRM] 완료" );
7497 return ConfirmResponse .from (sharing );
7598 }
99+
76100}
0 commit comments