Skip to content

Commit

Permalink
refactor: change function to send reserved mail
Browse files Browse the repository at this point in the history
  • Loading branch information
woowabrie committed Oct 19, 2023
1 parent dd427ec commit 0fe7829
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/apply/application/mail/MailMessageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime

@Transactional
@Service
class MailMessageService(
private val sendingMailService: SendingMailService,
Expand Down Expand Up @@ -43,6 +42,7 @@ class MailMessageService(
}
}

@Transactional
fun reserve(request: MailData): MailMessageResponse {
val mailMessage = mailMessageRepository.save(request.toMailMessage())
val mailReservation = mailReservationRepository.save(
Expand All @@ -51,6 +51,7 @@ class MailMessageService(
return MailMessageResponse(mailMessage, mailReservation)
}

@Transactional
fun cancelReservation(mailMessageId: Long) {
val mailReservation = mailReservationRepository.findByMailMessageId(mailMessageId)
?: throw IllegalArgumentException("메일 예약이 존재하지 않습니다. email: $mailMessageId")
Expand All @@ -67,10 +68,9 @@ class MailMessageService(
val messagesById = findMessageMapById(reservations.map { it.mailMessageId })

reservations.forEach { mailReservation ->
mailReservation.send()
mailReservationRepository.save(mailReservation)
sendingMailService.sendMailByBccSynchronous(MailData(messagesById.getValue(mailReservation.mailMessageId)))
mailReservation.finish()
mailReservationRepository.save(mailReservation)
}
}

Expand Down

0 comments on commit 0fe7829

Please sign in to comment.