Skip to content

Commit

Permalink
feat: Ability to provide destinations for contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
LotuxPunk committed Dec 28, 2024
1 parent 0466f3d commit 1d65e71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main/kotlin/com/vandeas/dto/ContactForm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sealed interface ContactForm {
val phone: String?
val topic: String?
val content: String
val destinations: List<String>
}

@SerialName(GOOGLE_RECAPTCHA_SERIAL_NAME)
Expand All @@ -29,6 +30,7 @@ data class GoogleRecaptchaContactForm(
override val content: String,
override val phone: String? = null,
override val topic: String? = null,
override val destinations: List<String> = emptyList(),
val recaptchaToken: String,
) : ContactForm

Expand All @@ -41,5 +43,6 @@ data class KerberusContactForm(
override val content: String,
override val phone: String? = null,
override val topic: String? = null,
override val destinations: List<String> = emptyList(),
val solution: Solution
) : ContactForm
24 changes: 19 additions & 5 deletions src/main/kotlin/com/vandeas/logic/impl/MailLogicImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,25 @@ class MailLogicImpl(

val mailer = mailers[config.identifierFromCredentials()] ?: config.toMailer().also { mailers[config.identifierFromCredentials()] = it }

return mailer.sendEmail(
from = config.sender,
to = config.destination,
subject = subjectTemplate.processToString(mapOf("form" to form)),
content = contentTemplate.processToString(mapOf("form" to form))
val subject = subjectTemplate.processToString(mapOf("form" to form))
val content = contentTemplate.processToString(mapOf("form" to form))

return mailer.sendEmails(
mails = form.destinations.takeIf { it.isNotEmpty() }?.map { destination ->
Mail(
from = config.sender,
to = destination,
subject = subject,
content = content
)
} ?: listOf(
Mail(
from = config.sender,
to = config.destination,
subject = subject,
content = content
)
)
)
}

Expand Down

0 comments on commit 1d65e71

Please sign in to comment.