@@ -74,39 +74,59 @@ class MailService(
7474 mailReservationReader.readAllBeforeBySenderEmails(now, senderEmails)
7575 }
7676 return reservations.map { reservation ->
77- val mail = mailRepository.findById(reservation.mailId) ? : run {
78- log.warn(" 예약의 메일을 찾을 수 없음: reservationId={}, mailId={}" , reservation.id, reservation.mailId)
79- return @map PendingMailReservationStatus (
80- reservationId = reservation.id!! ,
81- mailId = reservation.mailId,
82- reservationTime = reservation.reservationTime,
83- failureErrorCode = null ,
84- failedAt = null ,
85- )
86- }
87- val (failureErrorCode, failedAt) = try {
88- val senderUser =
89- userReader.findByEmail(mail.senderEmailAddress)
90- ? : run {
91- log.warn(
92- " 예약 발신자 사용자를 찾을 수 없음: reservationId={}, mailId={}, senderEmail={}" ,
93- reservation.id,
94- reservation.mailId,
95- mail.senderEmailAddress,
96- )
97- return @map PendingMailReservationStatus (
98- reservationId = reservation.id!! ,
99- mailId = reservation.mailId,
100- reservationTime = reservation.reservationTime,
101- failureErrorCode = null ,
102- failedAt = null ,
103- )
104- }
105- oauth2Service.refreshOAuth2TokenBeforeExpiry(senderUser.id!! , OAuth2Type .GOOGLE , 10L )
106- null to null
107- } catch (e: CustomException ) {
108- e.errorCode to now
109- }
77+ val mail =
78+ mailRepository.findById(reservation.mailId)
79+ ? : run {
80+ log.warn(" 예약의 메일을 찾을 수 없음: reservationId={}, mailId={}" , reservation.id, reservation.mailId)
81+ return @map PendingMailReservationStatus (
82+ reservationId = reservation.id!! ,
83+ mailId = reservation.mailId,
84+ reservationTime = reservation.reservationTime,
85+ failureErrorCode = null ,
86+ failedAt = null ,
87+ )
88+ }
89+ val (failureErrorCode, failedAt) =
90+ try {
91+ val senderUser =
92+ userReader.findByEmail(mail.senderEmailAddress)
93+ ? : run {
94+ log.warn(
95+ " 예약 발신자 사용자를 찾을 수 없음: reservationId={}, mailId={}, senderEmail={}" ,
96+ reservation.id,
97+ reservation.mailId,
98+ mail.senderEmailAddress,
99+ )
100+ return @map PendingMailReservationStatus (
101+ reservationId = reservation.id!! ,
102+ mailId = reservation.mailId,
103+ reservationTime = reservation.reservationTime,
104+ failureErrorCode = null ,
105+ failedAt = null ,
106+ )
107+ }
108+ val senderId =
109+ senderUser.id
110+ ? : run {
111+ log.warn(
112+ " 발신자 userId가 null: reservationId={}, mailId={}, senderEmail={}" ,
113+ reservation.id,
114+ reservation.mailId,
115+ mail.senderEmailAddress,
116+ )
117+ return @map PendingMailReservationStatus (
118+ reservationId = reservation.id!! ,
119+ mailId = reservation.mailId,
120+ reservationTime = reservation.reservationTime,
121+ failureErrorCode = null ,
122+ failedAt = null ,
123+ )
124+ }
125+ oauth2Service.refreshOAuth2TokenBeforeExpiry(senderId, OAuth2Type .GOOGLE , 10L )
126+ null to null
127+ } catch (e: CustomException ) {
128+ e.errorCode to now
129+ }
110130 PendingMailReservationStatus (
111131 reservationId = reservation.id!! ,
112132 mailId = reservation.mailId,
0 commit comments