Skip to content

Commit

Permalink
🎨 프로퍼티 이름 변경 jandi.default-webhook-url -> jandi.webhook-url. JandiAut…
Browse files Browse the repository at this point in the history
…oConfiguration 와 DefaultJandiService 의존성 제거
  • Loading branch information
이용홍 committed Mar 7, 2023
1 parent bfd7486 commit ff881b8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ class JandiAutoConfiguration {
restTemplate: RestTemplate,
properties: JandiProperties
): JandiService {
return DefaultJandiService(restTemplate, properties)
return DefaultJandiService(properties.webhookUrl, restTemplate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.boot.context.properties.ConstructorBinding
@ConstructorBinding
data class JandiProperties(
val enabled: Boolean = true,
val defaultWebhookUrl: String? = null,
val webhookUrl: String,
val webhook: Webhook = Webhook(true, DEFAULT_WEBHOOK_PATH)
) {
companion object {
Expand Down
12 changes: 4 additions & 8 deletions src/main/kotlin/herbaccara/jandi/DefaultJandiService.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package herbaccara.jandi

import com.fasterxml.jackson.databind.JsonNode
import herbaccara.boot.autoconfigure.jandi.JandiProperties
import herbaccara.jandi.model.JandiMessage
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.web.client.RestTemplate
import org.springframework.web.client.postForObject

class DefaultJandiService(
private val restTemplate: RestTemplate,
private val properties: JandiProperties
class DefaultJandiService @JvmOverloads constructor(
private val webhookUrl: String,
private val restTemplate: RestTemplate = RestTemplate()
) : JandiService {

override fun send(message: JandiMessage): JsonNode {
val defaultWebhookUrl = properties.defaultWebhookUrl
if (defaultWebhookUrl.isNullOrBlank()) throw RuntimeException("webhookUrl must not be empty")

return send(defaultWebhookUrl, message)
return send(webhookUrl, message)
}

override fun send(webhookUrl: String, message: JandiMessage): JsonNode {
Expand Down
25 changes: 25 additions & 0 deletions src/test/kotlin/herbaccara/jandi/DefaultJandiServiceTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package herbaccara.jandi

import herbaccara.jandi.model.ConnectInfo
import herbaccara.jandi.model.JandiMessage
import org.junit.jupiter.api.Test

class DefaultJandiServiceTest {

@Test
fun test() {
val jandiService =
DefaultJandiService("")

jandiService.send(
JandiMessage(
"[[PizzaHouse]](http://url_to_text) You have a new Pizza order.",
"#FAC11B",
listOf(
ConnectInfo("Topping", "Pepperoni"),
ConnectInfo("Location", "Empire State Building, 5th Ave, New York", "http://url_to_text")
)
)
)
}
}
2 changes: 1 addition & 1 deletion src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jandi:
enabled: true
default-webhook-url:
webhook-url:
webhook:
enabled: true
path: /jandi/webhook

0 comments on commit ff881b8

Please sign in to comment.