-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: Jsoup 의존성 추가 * refactor: BrowseTemplateUseCase 리펙토링 * refactor: SendNotificationEmailUseCase 리펙토링 * feat: HtmlValidator 구현 * feat: PostEmailTemplateEvent 구현 * refactor: PostTemplateUseCase 리펙토링 * refactor: EnrollUserUseCase 리펙토링 * refactor: 뷰에 경고창 생성 추가
- Loading branch information
1 parent
af88ccc
commit de7f7cb
Showing
12 changed files
with
352 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
domain/crm/src/main/kotlin/com/few/crm/email/event/template/EmailTemplateTransactionEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.few.crm.email.event.template | ||
|
||
import event.Event | ||
import event.EventUtils | ||
|
||
abstract class EmailTemplateTransactionEvent( | ||
eventId: String = EventUtils.generateEventId(), | ||
eventType: String, | ||
eventTime: Long = System.currentTimeMillis(), | ||
) : Event( | ||
eventId = eventId, | ||
eventType = eventType, | ||
eventTime = eventTime, | ||
) | ||
|
||
abstract class EmailTemplateTransactionAfterCompletionEvent( | ||
eventId: String = EventUtils.generateEventId(), | ||
eventType: String, | ||
eventTime: Long = System.currentTimeMillis(), | ||
) : EmailTemplateTransactionEvent( | ||
eventId = eventId, | ||
eventType = eventType, | ||
eventTime = eventTime, | ||
) | ||
|
||
class PostEmailTemplateEvent( | ||
val templateId: Long, | ||
eventId: String = EventUtils.generateEventId(), | ||
eventType: String, | ||
eventTime: Long = System.currentTimeMillis(), | ||
) : EmailTemplateTransactionAfterCompletionEvent( | ||
eventType = "PostEmailTemplateEvent", | ||
) { | ||
override fun getData(): Map<String, Any> = | ||
mapOf( | ||
"templateId" to templateId, | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
.../crm/src/main/kotlin/com/few/crm/email/event/template/EventTemplateTransactionListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.few.crm.email.event.template | ||
|
||
import com.few.crm.email.event.template.handler.PostEmailTemplateEventHandler | ||
import com.few.crm.support.jpa.CrmTransactional | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Propagation | ||
import org.springframework.transaction.event.TransactionPhase | ||
import org.springframework.transaction.event.TransactionalEventListener | ||
|
||
@Component | ||
class EventTemplateTransactionListener( | ||
private val postEmailTemplateEventHandler: PostEmailTemplateEventHandler, | ||
) { | ||
@Async | ||
@CrmTransactional(propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMPLETION) | ||
fun handleAfterCompletionEvent(event: EmailTemplateTransactionAfterCompletionEvent) { | ||
when (event) { | ||
is PostEmailTemplateEvent -> postEmailTemplateEventHandler.handle(event) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...src/main/kotlin/com/few/crm/email/event/template/handler/PostEmailTemplateEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.few.crm.email.event.template.handler | ||
|
||
import com.few.crm.email.domain.EmailTemplateHistory | ||
import com.few.crm.email.event.template.PostEmailTemplateEvent | ||
import com.few.crm.email.repository.EmailTemplateHistoryRepository | ||
import com.few.crm.email.repository.EmailTemplateRepository | ||
import com.few.crm.support.jpa.CrmTransactional | ||
import event.EventHandler | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class PostEmailTemplateEventHandler( | ||
private val emailTemplateRepository: EmailTemplateRepository, | ||
private val emailTemplateHistoryRepository: EmailTemplateHistoryRepository, | ||
) : EventHandler<PostEmailTemplateEvent> { | ||
@CrmTransactional | ||
override fun handle(event: PostEmailTemplateEvent) { | ||
val templateId = event.templateId | ||
val template = | ||
emailTemplateRepository | ||
.findById(templateId) | ||
.orElseThrow { IllegalArgumentException("EmailTemplate not found for id: $templateId") } | ||
emailTemplateHistoryRepository.save( | ||
EmailTemplateHistory( | ||
templateId = template.id!!, | ||
subject = template.subject, | ||
body = template.body, | ||
variables = template.variables, | ||
version = template.version, | ||
), | ||
) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
domain/crm/src/main/kotlin/com/few/crm/email/service/HtmlValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.few.crm.email.service | ||
|
||
import org.jsoup.Jsoup | ||
import org.jsoup.nodes.Document | ||
import org.jsoup.parser.Parser | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class HtmlValidator { | ||
fun isValidHtml(input: String): Boolean = | ||
try { | ||
Jsoup.parse(input, "", Parser.htmlParser()) | ||
true | ||
} catch (e: Exception) { | ||
false | ||
} | ||
|
||
fun prettyPrintHtml(input: String): String? = | ||
try { | ||
val document: Document = Jsoup.parse(input, "", Parser.htmlParser()) | ||
document.normalise() | ||
document.outerHtml() | ||
} catch (e: Exception) { | ||
null | ||
} | ||
|
||
fun extractVariables(input: String): List<String> { | ||
val document: Document = Jsoup.parse(input, "", Parser.htmlParser()) | ||
val variables = mutableSetOf<String>() // 중복 제거를 위해 Set 사용 | ||
|
||
document.allElements.forEach { element -> | ||
element.attributes().forEach { attr -> | ||
val value = attr.value | ||
val regex = """\$\{([a-zA-Z0-9_.]+)}""".toRegex() | ||
regex.findAll(value).forEach { matchResult -> | ||
variables.add(matchResult.groupValues[1]) | ||
} | ||
} | ||
} | ||
|
||
return variables.toList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.