From 31794b2ac0d4bbc38df8e8590e895f0a746950c1 Mon Sep 17 00:00:00 2001 From: le2sky Date: Sun, 1 Oct 2023 22:33:30 +0900 Subject: [PATCH 01/25] =?UTF-8?q?refactor=20:=20WebClientConfig=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mealkitary-api/build.gradle.kts | 1 + .../adapter-configuration/build.gradle.kts | 3 +++ .../src/main/kotlin/com/mealkitary/config}/WebClientConfig.kt | 2 +- settings.gradle.kts | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 mealkitary-infrastructure/adapter-configuration/build.gradle.kts rename mealkitary-infrastructure/{adapter-paymentgateway-tosspayments/src/main/kotlin/com/mealkitary/paymentgateway => adapter-configuration/src/main/kotlin/com/mealkitary/config}/WebClientConfig.kt (97%) diff --git a/mealkitary-api/build.gradle.kts b/mealkitary-api/build.gradle.kts index 5ffe9a6..a089801 100644 --- a/mealkitary-api/build.gradle.kts +++ b/mealkitary-api/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { implementation(project(":mealkitary-infrastructure:adapter-persistence-spring-data-jpa")) implementation(project(":mealkitary-infrastructure:adapter-paymentgateway-tosspayments")) implementation(project(":mealkitary-infrastructure:adapter-firebase-notification")) + implementation(project(":mealkitary-infrastructure:adapter-configuration")) implementation( project( ":mealkitary-infrastructure:business-registration-number-validator:adapter-open-api-brn-validator", diff --git a/mealkitary-infrastructure/adapter-configuration/build.gradle.kts b/mealkitary-infrastructure/adapter-configuration/build.gradle.kts new file mode 100644 index 0000000..044d087 --- /dev/null +++ b/mealkitary-infrastructure/adapter-configuration/build.gradle.kts @@ -0,0 +1,3 @@ +dependencies { + implementation("org.springframework.boot:spring-boot-starter-webflux") +} diff --git a/mealkitary-infrastructure/adapter-paymentgateway-tosspayments/src/main/kotlin/com/mealkitary/paymentgateway/WebClientConfig.kt b/mealkitary-infrastructure/adapter-configuration/src/main/kotlin/com/mealkitary/config/WebClientConfig.kt similarity index 97% rename from mealkitary-infrastructure/adapter-paymentgateway-tosspayments/src/main/kotlin/com/mealkitary/paymentgateway/WebClientConfig.kt rename to mealkitary-infrastructure/adapter-configuration/src/main/kotlin/com/mealkitary/config/WebClientConfig.kt index 77c87d4..08bfe96 100644 --- a/mealkitary-infrastructure/adapter-paymentgateway-tosspayments/src/main/kotlin/com/mealkitary/paymentgateway/WebClientConfig.kt +++ b/mealkitary-infrastructure/adapter-configuration/src/main/kotlin/com/mealkitary/config/WebClientConfig.kt @@ -1,4 +1,4 @@ -package com.mealkitary.paymentgateway +package com.mealkitary.config import io.netty.channel.ChannelOption import io.netty.handler.timeout.ReadTimeoutHandler diff --git a/settings.gradle.kts b/settings.gradle.kts index 52db22b..8d5f11b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,6 +7,7 @@ include( "mealkitary-infrastructure:adapter-persistence-spring-data-jpa", "mealkitary-infrastructure:adapter-paymentgateway-tosspayments", "mealkitary-infrastructure:adapter-firebase-notification", + "mealkitary-infrastructure:adapter-configuration", "mealkitary-infrastructure:business-registration-number-validator:adapter-open-api-brn-validator", "mealkitary-infrastructure:business-registration-number-validator:adapter-simple-brn-validator" ) From 9a548ff46d302882c9a45d2b0a9e537e09a603b8 Mon Sep 17 00:00:00 2001 From: le2sky Date: Sun, 1 Oct 2023 22:36:59 +0900 Subject: [PATCH 02/25] =?UTF-8?q?refactor=20:=20brn=20=EC=96=B4=EB=8C=91?= =?UTF-8?q?=ED=84=B0=20=EB=AA=A8=EB=93=88=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mealkitary-api/build.gradle.kts | 4 ++-- .../open-api-brn-validator}/build.gradle.kts | 0 .../simple-brn-validator}/build.gradle.kts | 0 .../src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt | 0 .../test/kotlin/com/mealkitary/brn/SimpleBrnValidatorTest.kt | 0 settings.gradle.kts | 4 ++-- 6 files changed, 4 insertions(+), 4 deletions(-) rename mealkitary-infrastructure/{business-registration-number-validator/adapter-open-api-brn-validator => adapter-business-registration-number-validator/open-api-brn-validator}/build.gradle.kts (100%) rename mealkitary-infrastructure/{business-registration-number-validator/adapter-simple-brn-validator => adapter-business-registration-number-validator/simple-brn-validator}/build.gradle.kts (100%) rename mealkitary-infrastructure/{business-registration-number-validator/adapter-simple-brn-validator => adapter-business-registration-number-validator/simple-brn-validator}/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt (100%) rename mealkitary-infrastructure/{business-registration-number-validator/adapter-simple-brn-validator => adapter-business-registration-number-validator/simple-brn-validator}/src/test/kotlin/com/mealkitary/brn/SimpleBrnValidatorTest.kt (100%) diff --git a/mealkitary-api/build.gradle.kts b/mealkitary-api/build.gradle.kts index a089801..06edb2d 100644 --- a/mealkitary-api/build.gradle.kts +++ b/mealkitary-api/build.gradle.kts @@ -24,12 +24,12 @@ dependencies { implementation(project(":mealkitary-infrastructure:adapter-configuration")) implementation( project( - ":mealkitary-infrastructure:business-registration-number-validator:adapter-open-api-brn-validator", + ":mealkitary-infrastructure:adapter-business-registration-number-validator:open-api-brn-validator", ) ) implementation( project( - ":mealkitary-infrastructure:business-registration-number-validator:adapter-simple-brn-validator", + ":mealkitary-infrastructure:adapter-business-registration-number-validator:simple-brn-validator", ) ) testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc") diff --git a/mealkitary-infrastructure/business-registration-number-validator/adapter-open-api-brn-validator/build.gradle.kts b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build.gradle.kts similarity index 100% rename from mealkitary-infrastructure/business-registration-number-validator/adapter-open-api-brn-validator/build.gradle.kts rename to mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build.gradle.kts diff --git a/mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build.gradle.kts b/mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build.gradle.kts similarity index 100% rename from mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build.gradle.kts rename to mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build.gradle.kts diff --git a/mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt similarity index 100% rename from mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt rename to mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt diff --git a/mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/src/test/kotlin/com/mealkitary/brn/SimpleBrnValidatorTest.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/test/kotlin/com/mealkitary/brn/SimpleBrnValidatorTest.kt similarity index 100% rename from mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/src/test/kotlin/com/mealkitary/brn/SimpleBrnValidatorTest.kt rename to mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/test/kotlin/com/mealkitary/brn/SimpleBrnValidatorTest.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index 8d5f11b..ff37a8e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,8 +8,8 @@ include( "mealkitary-infrastructure:adapter-paymentgateway-tosspayments", "mealkitary-infrastructure:adapter-firebase-notification", "mealkitary-infrastructure:adapter-configuration", - "mealkitary-infrastructure:business-registration-number-validator:adapter-open-api-brn-validator", - "mealkitary-infrastructure:business-registration-number-validator:adapter-simple-brn-validator" + "mealkitary-infrastructure:adapter-business-registration-number-validator:open-api-brn-validator", + "mealkitary-infrastructure:adapter-business-registration-number-validator:simple-brn-validator" ) pluginManagement { From f2a32f774b2be1385ca3dbd29f4dc49625183d6a Mon Sep 17 00:00:00 2001 From: le2sky Date: Sun, 1 Oct 2023 22:40:10 +0900 Subject: [PATCH 03/25] =?UTF-8?q?refactor=20:=20=EB=AA=A8=EB=93=88=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/mealkitary-main-develop-ci.yml | 4 ++-- .github/workflows/mealkitary-test-coverage-automation.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mealkitary-main-develop-ci.yml b/.github/workflows/mealkitary-main-develop-ci.yml index 901d7f2..4d26e2c 100644 --- a/.github/workflows/mealkitary-main-develop-ci.yml +++ b/.github/workflows/mealkitary-main-develop-ci.yml @@ -54,7 +54,7 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-firebase-notification/build/test-results/**/*.xml - ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/test-results/**/*.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/test-results/**/*.xml - name: Jacoco Coverage 리포트 전송 uses: codecov/codecov-action@v3 @@ -67,7 +67,7 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-firebase-notification/build/reports/jacoco/test/jacocoTestReport.xml, - ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml name: mealkitary-codecov verbose: true diff --git a/.github/workflows/mealkitary-test-coverage-automation.yml b/.github/workflows/mealkitary-test-coverage-automation.yml index acd71d2..e8e2a8d 100644 --- a/.github/workflows/mealkitary-test-coverage-automation.yml +++ b/.github/workflows/mealkitary-test-coverage-automation.yml @@ -42,7 +42,7 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-firebase-notification/build/test-results/**/*.xml - ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/test-results/**/*.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/test-results/**/*.xml - name: Jacoco Coverage 리포트 전송 uses: codecov/codecov-action@v3 @@ -55,6 +55,6 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-firebase-notification/build/reports/jacoco/test/jacocoTestReport.xml, - ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml name: mealkitary-codecov verbose: true From a5ad0efe4d78a4982d0102b97f979a6ded1e7924 Mon Sep 17 00:00:00 2001 From: le2sky Date: Mon, 2 Oct 2023 04:27:00 +0900 Subject: [PATCH 04/25] =?UTF-8?q?chore=20:=20uriBuilderFactory=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/config/WebClientConfig.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mealkitary-infrastructure/adapter-configuration/src/main/kotlin/com/mealkitary/config/WebClientConfig.kt b/mealkitary-infrastructure/adapter-configuration/src/main/kotlin/com/mealkitary/config/WebClientConfig.kt index 08bfe96..0f0efe3 100644 --- a/mealkitary-infrastructure/adapter-configuration/src/main/kotlin/com/mealkitary/config/WebClientConfig.kt +++ b/mealkitary-infrastructure/adapter-configuration/src/main/kotlin/com/mealkitary/config/WebClientConfig.kt @@ -8,6 +8,8 @@ import org.springframework.context.annotation.Configuration import org.springframework.http.client.reactive.ReactorClientHttpConnector import org.springframework.web.reactive.function.client.ExchangeStrategies import org.springframework.web.reactive.function.client.WebClient +import org.springframework.web.util.DefaultUriBuilderFactory +import org.springframework.web.util.UriBuilderFactory import reactor.netty.http.client.HttpClient import java.time.Duration import java.util.concurrent.TimeUnit @@ -19,10 +21,24 @@ class WebClientConfig { @Bean fun webClient() = WebClient.builder() + .uriBuilderFactory(uriBuilderFactory()) .exchangeStrategies(exchangeStrategies()) .clientConnector(ReactorClientHttpConnector(httpClient())) .build() + private fun uriBuilderFactory(): UriBuilderFactory { + val factory = DefaultUriBuilderFactory() + factory.encodingMode = DefaultUriBuilderFactory.EncodingMode.NONE + + return factory + } + + private fun exchangeStrategies() = ExchangeStrategies.builder() + .codecs { configurer -> + configurer.defaultCodecs().maxInMemorySize(TEEN_MEGA_BYTE) + } + .build() + private fun httpClient() = HttpClient.create() .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) .responseTimeout(Duration.ofMillis(5000)) @@ -31,10 +47,4 @@ class WebClientConfig { .addHandlerLast(ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) .addHandlerLast(WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)) } - - private fun exchangeStrategies() = ExchangeStrategies.builder() - .codecs { configurer -> - configurer.defaultCodecs().maxInMemorySize(TEEN_MEGA_BYTE) - } - .build() } From 8e4b13919722eadbd59b6d4c1551c1aa829540a0 Mon Sep 17 00:00:00 2001 From: le2sky Date: Tue, 3 Oct 2023 02:58:11 +0900 Subject: [PATCH 05/25] =?UTF-8?q?feat=20:=20open=20api=20brn=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/brn/OpenApiBrnValidator.kt | 40 +++++++++ .../mealkitary/brn/OpenApiBrnValidatorTest.kt | 82 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt create mode 100644 mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiBrnValidatorTest.kt diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt new file mode 100644 index 0000000..e0f2630 --- /dev/null +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt @@ -0,0 +1,40 @@ +package com.mealkitary.brn + +import com.mealkitary.brn.payload.OpenApiBrnStatusPayload +import com.mealkitary.brn.payload.OpenApiBrnStatusResponse +import com.mealkitary.shop.domain.shop.ShopBusinessNumber +import com.mealkitary.shop.domain.shop.factory.ShopBusinessNumberValidator +import org.springframework.stereotype.Component + +@Component +class OpenApiBrnValidator( + private val openApiWebClient: OpenApiWebClient +) : ShopBusinessNumberValidator { + + override fun validate(brn: ShopBusinessNumber) { + val brnValue = removeDelimiter(brn.value) + + val openApiStatusResponse = openApiWebClient.requestStatus( + OpenApiBrnStatusPayload(listOf(brnValue)), + "https://api.odcloud.kr/api/nts-businessman" + ) + + checkHasResult(openApiStatusResponse) + checkBrnStatus(openApiStatusResponse) + } + + private fun removeDelimiter(brn: String) = brn.replace("-", "") + + private fun checkHasResult(openApiBrnStatusResponse: OpenApiBrnStatusResponse) { + if (openApiBrnStatusResponse.data.isEmpty()) { + throw IllegalArgumentException("사업자 번호 조회 결과가 없습니다.") + } + } + + private fun checkBrnStatus(openApiBrnStatusResponse: OpenApiBrnStatusResponse) { + val result = openApiBrnStatusResponse.data[0] + if (result.b_stt != "계속사업자") { + throw IllegalArgumentException("유효하지 않은 사업자 번호입니다.") + } + } +} diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiBrnValidatorTest.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiBrnValidatorTest.kt new file mode 100644 index 0000000..5b73ae9 --- /dev/null +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiBrnValidatorTest.kt @@ -0,0 +1,82 @@ +package com.mealkitary.brn + +import com.mealkitary.brn.payload.OpenApiBrnStatus +import com.mealkitary.brn.payload.OpenApiBrnStatusPayload +import com.mealkitary.brn.payload.OpenApiBrnStatusResponse +import com.mealkitary.shop.domain.shop.ShopBusinessNumber +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.AnnotationSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.throwable.shouldHaveMessage +import io.mockk.every +import io.mockk.mockk +import io.mockk.slot +import io.mockk.verify + +class OpenApiBrnValidatorTest : AnnotationSpec() { + + private val openApiWebClient = mockk() + private val openApiBrnValidator = OpenApiBrnValidator(openApiWebClient) + + @Test + fun `Open API 호출할 때, 사업자 등록 번호의 하이픈(-)을 제거한다`() { + val payloadSlot = slot() + every { openApiWebClient.requestStatus(capture(payloadSlot), any()) } answers { + createResponse("계속사업자") + } + + openApiBrnValidator.validate(ShopBusinessNumber.from("123-12-12345")) + + val captured = payloadSlot.captured + captured.b_no.get(0) shouldBe "1231212345" + } + + @Test + fun `사업자 번호 조회 결과가 존재하지 않는다면 예외를 발생한다`() { + every { openApiWebClient.requestStatus(any(), any()) } answers { + OpenApiBrnStatusResponse( + "OK", + 0, + 0, + emptyList() + ) + } + + shouldThrow { + openApiBrnValidator.validate(ShopBusinessNumber.from("123-12-12345")) + } shouldHaveMessage "사업자 번호 조회 결과가 없습니다." + } + + @Test + fun `사업자 상태가 계속사업자가 아니라면 예외를 발생한다`() { + every { openApiWebClient.requestStatus(any(), any()) } answers { + createResponse("휴업자") + } + + shouldThrow { + openApiBrnValidator.validate(ShopBusinessNumber.from("123-12-12345")) + } shouldHaveMessage "유효하지 않은 사업자 번호입니다." + } + + @Test + fun `HTTP 클라이언트에게 Open API 경로를 전달한다`() { + every { openApiWebClient.requestStatus(any(), any()) } answers { + createResponse("계속사업자") + } + + openApiBrnValidator.validate(ShopBusinessNumber.from("123-12-12345")) + + verify { openApiWebClient.requestStatus(any(), "https://api.odcloud.kr/api/nts-businessman") } + } + + private fun createResponse(b_stt: String) = OpenApiBrnStatusResponse( + "OK", + 0, + 0, + listOf( + OpenApiBrnStatus( + "", b_stt, "", "", "", "", "", "", "", "", "" + ) + ) + ) +} From 5cbb3423c6101d7a022328518dc53ce428b3c13d Mon Sep 17 00:00:00 2001 From: le2sky Date: Tue, 3 Oct 2023 02:59:20 +0900 Subject: [PATCH 06/25] =?UTF-8?q?feat=20:=20open=20api=20webclient=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/brn/OpenApiWebClient.kt | 44 +++++++++ .../mealkitary/brn/OpenApiWebClientTest.kt | 94 +++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiWebClient.kt create mode 100644 mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiWebClientTest.kt diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiWebClient.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiWebClient.kt new file mode 100644 index 0000000..e6caee2 --- /dev/null +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiWebClient.kt @@ -0,0 +1,44 @@ +package com.mealkitary.brn + +import com.mealkitary.brn.payload.OpenApiBrnStatusPayload +import com.mealkitary.brn.payload.OpenApiBrnStatusResponse +import org.springframework.beans.factory.annotation.Value +import org.springframework.http.HttpHeaders +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.stereotype.Component +import org.springframework.web.reactive.function.client.WebClient +import reactor.core.publisher.Mono +import java.nio.charset.StandardCharsets + +@Component +class OpenApiWebClient( + private val webClient: WebClient, + @Value("\${openapi.brn.serviceKey}") + private val serviceKey: String +) { + + fun requestStatus(payload: OpenApiBrnStatusPayload, baseUrl: String): OpenApiBrnStatusResponse { + val openApiBrnStatusResponse = webClient.post() + .uri("$baseUrl/v1/status?serviceKey=$serviceKey") + .headers { setHeader(it) } + .body(Mono.just(payload), OpenApiBrnStatusPayload::class.java) + .exchangeToMono { + if (it.statusCode() == HttpStatus.OK) { + it.bodyToMono(OpenApiBrnStatusResponse::class.java) + } else { + Mono.error(RuntimeException()) + } + } + .block() + + return openApiBrnStatusResponse!! + } + + private fun setHeader( + headers: HttpHeaders, + ) { + headers.acceptCharset = listOf(StandardCharsets.UTF_8) + headers.contentType = MediaType.APPLICATION_JSON + } +} diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiWebClientTest.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiWebClientTest.kt new file mode 100644 index 0000000..4011ea6 --- /dev/null +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/test/kotlin/com/mealkitary/brn/OpenApiWebClientTest.kt @@ -0,0 +1,94 @@ +package com.mealkitary.brn + +import com.fasterxml.jackson.databind.ObjectMapper +import com.mealkitary.brn.payload.OpenApiBrnStatus +import com.mealkitary.brn.payload.OpenApiBrnStatusPayload +import com.mealkitary.brn.payload.OpenApiBrnStatusResponse +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.AnnotationSpec +import io.kotest.inspectors.forAll +import io.kotest.matchers.shouldBe +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.MockWebServer +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.web.reactive.function.client.WebClient + +class OpenApiWebClientTest : AnnotationSpec() { + + private lateinit var mockWebServer: MockWebServer + private lateinit var webClient: WebClient + private lateinit var openApiWebClient: OpenApiWebClient + private val objectMapper = ObjectMapper() + + @BeforeEach + fun setUp() { + mockWebServer = MockWebServer() + mockWebServer.start() + webClient = WebClient.builder() + .baseUrl(mockWebServer.url("").toString()) + .codecs { configurer -> + configurer.defaultCodecs().maxInMemorySize(5 * 1024 * 1024) + } + .defaultHeaders { headers -> + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) + } + .build() + + openApiWebClient = OpenApiWebClient(webClient, "serviceKey") + } + + @AfterEach + fun teardown() { + mockWebServer.shutdown() + } + + @Test + fun `200 OK를 받으면 아무 예외도 발생하지 않는다`() { + val expectedPath = "/v1/status?serviceKey=serviceKey" + mockWebServer.enqueue( + MockResponse() + .setBody(objectMapper.writeValueAsString(createResponse())) + .setResponseCode(200) + .addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + ) + + openApiWebClient.requestStatus(OpenApiBrnStatusPayload(listOf("1232323456")), mockWebServer.url("").toString()) + + val recordedRequest = mockWebServer.takeRequest() + recordedRequest.path shouldBe expectedPath + recordedRequest.method shouldBe "POST" + recordedRequest.body.toString().contains("1232323456") + } + + @Test + fun `200이 아닌 코드는 RuntimeException으로 처리한다`() { + listOf(300, 400, 401, 500).forAll { + mockWebServer.enqueue( + MockResponse() + .setResponseCode(it) + .setBody(objectMapper.writeValueAsString(createResponse())) + .addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + ) + + shouldThrow { + openApiWebClient.requestStatus( + OpenApiBrnStatusPayload(listOf("1232323456")), + mockWebServer.url("").toString() + ) + } + } + } + + private fun createResponse() = OpenApiBrnStatusResponse( + "OK", + 0, + 0, + listOf( + OpenApiBrnStatus( + "", "계속사업자", "", "", "", "", "", "", "", "", "" + ) + ) + ) +} From a9dd64e95858dd92cde05f35bde73cc63f169d12 Mon Sep 17 00:00:00 2001 From: le2sky Date: Tue, 3 Oct 2023 02:59:43 +0900 Subject: [PATCH 07/25] =?UTF-8?q?feat=20:=20http=20=EC=9A=94=EC=B2=AD/?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=ED=8E=98=EC=9D=B4=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mealkitary/brn/payload/OpenApiBrnStatus.kt | 15 +++++++++++++++ .../brn/payload/OpenApiBrnStatusPayload.kt | 5 +++++ .../brn/payload/OpenApiBrnStatusResponse.kt | 8 ++++++++ 3 files changed, 28 insertions(+) create mode 100644 mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatus.kt create mode 100644 mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusPayload.kt create mode 100644 mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusResponse.kt diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatus.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatus.kt new file mode 100644 index 0000000..df4a5f2 --- /dev/null +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatus.kt @@ -0,0 +1,15 @@ +package com.mealkitary.brn.payload + +class OpenApiBrnStatus( + val b_no: String, + val b_stt: String, + val b_stt_cd: String, + val tax_type: String, + val tax_type_cd: String, + val end_dt: String, + val utcc_yn: String, + val tax_type_change_dt: String, + val invoice_apply_dt: String, + val rbf_tax_type: String, + val rbf_tax_type_cd: String +) diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusPayload.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusPayload.kt new file mode 100644 index 0000000..a9d3665 --- /dev/null +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusPayload.kt @@ -0,0 +1,5 @@ +package com.mealkitary.brn.payload + +class OpenApiBrnStatusPayload( + val b_no: List +) diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusResponse.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusResponse.kt new file mode 100644 index 0000000..4ad312b --- /dev/null +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/payload/OpenApiBrnStatusResponse.kt @@ -0,0 +1,8 @@ +package com.mealkitary.brn.payload + +class OpenApiBrnStatusResponse( + val status_code: String, + val match_cnt: Int, + val request_cnt: Int, + val data: List +) From 6984274c2f9a95bc639588052f9ee358e403aed4 Mon Sep 17 00:00:00 2001 From: le2sky Date: Tue, 3 Oct 2023 03:00:05 +0900 Subject: [PATCH 08/25] =?UTF-8?q?chore=20:=20webflux=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open-api-brn-validator/build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build.gradle.kts b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build.gradle.kts index c685d19..a989f72 100644 --- a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build.gradle.kts +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build.gradle.kts @@ -1,3 +1,7 @@ dependencies { + val mockWebServerVersion: String by properties + implementation("org.springframework.boot:spring-boot-starter-webflux") implementation(project(":mealkitary-domain")) + testImplementation("com.squareup.okhttp3:mockwebserver:$mockWebServerVersion") + testImplementation("io.projectreactor:reactor-test") } From e7e8d027bc896ab351d8270368af1b4115ee9224 Mon Sep 17 00:00:00 2001 From: le2sky Date: Tue, 3 Oct 2023 03:04:19 +0900 Subject: [PATCH 09/25] =?UTF-8?q?fix=20:=20bean=20=EC=A3=BC=EC=9E=85=20?= =?UTF-8?q?=EC=9A=B0=EC=84=A0=EC=88=9C=EC=9C=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt | 2 ++ .../src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt index e0f2630..a837ac9 100644 --- a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt @@ -4,8 +4,10 @@ import com.mealkitary.brn.payload.OpenApiBrnStatusPayload import com.mealkitary.brn.payload.OpenApiBrnStatusResponse import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.factory.ShopBusinessNumberValidator +import org.springframework.context.annotation.Primary import org.springframework.stereotype.Component +@Primary @Component class OpenApiBrnValidator( private val openApiWebClient: OpenApiWebClient diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt index 8010671..8417d87 100644 --- a/mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/src/main/kotlin/com/mealkitary/brn/SimpleBrnValidator.kt @@ -2,11 +2,9 @@ package com.mealkitary.brn import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.factory.ShopBusinessNumberValidator -import org.springframework.context.annotation.Primary import org.springframework.stereotype.Component @Component -@Primary class SimpleBrnValidator : ShopBusinessNumberValidator { override fun validate(brn: ShopBusinessNumber) {} From 5a6e771b44f8c934b0a26eb7d07a996235fde7c2 Mon Sep 17 00:00:00 2001 From: le2sky Date: Tue, 3 Oct 2023 03:05:45 +0900 Subject: [PATCH 10/25] =?UTF-8?q?fix=20:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EB=B2=84=EC=A0=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 26aeb68..a8bc6e7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ ktlintVersion=11.0.0 springBootVersion=2.7.11 springDependencyManagementVersion=1.0.15.RELEASE # project -applicationVersion=0.5.0 +applicationVersion=0.5.1 projectGroup=com.mealkitary # test kotestVersion=4.4.3 From 7ef0cccddb3c21d2f29b82f18fde2459e8814fd1 Mon Sep 17 00:00:00 2001 From: le2sky Date: Tue, 3 Oct 2023 03:08:30 +0900 Subject: [PATCH 11/25] =?UTF-8?q?fix=20:=20=EC=8B=A0=EA=B7=9C=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BB=A4=EB=B2=84?= =?UTF-8?q?=EB=A6=AC=EC=A7=80=20=EB=B6=84=EC=84=9D=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/mealkitary-main-develop-ci.yml | 4 +++- .github/workflows/mealkitary-test-coverage-automation.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mealkitary-main-develop-ci.yml b/.github/workflows/mealkitary-main-develop-ci.yml index 4d26e2c..477bef3 100644 --- a/.github/workflows/mealkitary-main-develop-ci.yml +++ b/.github/workflows/mealkitary-main-develop-ci.yml @@ -55,6 +55,7 @@ jobs: ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-firebase-notification/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/test-results/**/*.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build/test-results/**/*.xml - name: Jacoco Coverage 리포트 전송 uses: codecov/codecov-action@v3 @@ -67,7 +68,8 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-firebase-notification/build/reports/jacoco/test/jacocoTestReport.xml, - ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml, + ./mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml name: mealkitary-codecov verbose: true diff --git a/.github/workflows/mealkitary-test-coverage-automation.yml b/.github/workflows/mealkitary-test-coverage-automation.yml index e8e2a8d..def270f 100644 --- a/.github/workflows/mealkitary-test-coverage-automation.yml +++ b/.github/workflows/mealkitary-test-coverage-automation.yml @@ -43,6 +43,7 @@ jobs: ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-firebase-notification/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/test-results/**/*.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build/test-results/**/*.xml - name: Jacoco Coverage 리포트 전송 uses: codecov/codecov-action@v3 @@ -55,6 +56,7 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-firebase-notification/build/reports/jacoco/test/jacocoTestReport.xml, - ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml + ./mealkitary-infrastructure/adapter-business-registration-number-validator/simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml, + ./mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml name: mealkitary-codecov verbose: true From 0a56e962c8263a64d7944f522435e2b86b12cb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 11:53:35 +0900 Subject: [PATCH 12/25] =?UTF-8?q?refactor:=20=EA=B0=80=EA=B2=8C=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=9C=EC=97=90=20=EC=A3=BC=EC=86=8C?= =?UTF-8?q?=EB=8F=84=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/request/RegisterShopWebRequest.kt | 7 ++- .../shop/RegisterShopControllerDocsTest.kt | 3 +- .../shop/web/RegisterShopControllerTest.kt | 22 +++++++-- .../port/input/RegisterShopRequest.kt | 3 +- .../service/RegisterShopService.kt | 14 +++--- .../application/service/GetShopServiceTest.kt | 16 +++++++ .../service/RegisterShopServiceTest.kt | 48 +++++++++++++++++-- .../service/UpdateShopStatusServiceTest.kt | 42 ++++++++++++++++ 8 files changed, 136 insertions(+), 19 deletions(-) diff --git a/mealkitary-api/src/main/kotlin/com/mealkitary/shop/web/request/RegisterShopWebRequest.kt b/mealkitary-api/src/main/kotlin/com/mealkitary/shop/web/request/RegisterShopWebRequest.kt index 034c616..2cdc615 100644 --- a/mealkitary-api/src/main/kotlin/com/mealkitary/shop/web/request/RegisterShopWebRequest.kt +++ b/mealkitary-api/src/main/kotlin/com/mealkitary/shop/web/request/RegisterShopWebRequest.kt @@ -8,8 +8,11 @@ data class RegisterShopWebRequest( val title: String? = null, @field:NotBlank(message = "사업자 번호는 필수입니다.") - val brn: String? = null + val brn: String? = null, + + @field:NotBlank(message = "주소는 필수입니다.") + val address: String? = null ) { - fun mapToServiceRequest() = RegisterShopRequest(title!!, brn!!) + fun mapToServiceRequest() = RegisterShopRequest(title!!, brn!!, address!!) } diff --git a/mealkitary-api/src/test/kotlin/com/docs/shop/RegisterShopControllerDocsTest.kt b/mealkitary-api/src/test/kotlin/com/docs/shop/RegisterShopControllerDocsTest.kt index 7006d8f..c00ef51 100644 --- a/mealkitary-api/src/test/kotlin/com/docs/shop/RegisterShopControllerDocsTest.kt +++ b/mealkitary-api/src/test/kotlin/com/docs/shop/RegisterShopControllerDocsTest.kt @@ -28,7 +28,7 @@ class RegisterShopControllerDocsTest : RestDocsSupport() { fun `api docs test - registerShop`() { every { registerShopUseCase.register(any()) } answers { 1L } - val registerShopWebRequest = RegisterShopWebRequest("집밥뚝딱 안양점", "123-23-12345") + val registerShopWebRequest = RegisterShopWebRequest("집밥뚝딱 안양점", "123-23-12345", "경기도 안양시 동안구 벌말로") mvc.perform( RestDocumentationRequestBuilders.post("/shops") @@ -45,6 +45,7 @@ class RegisterShopControllerDocsTest : RestDocsSupport() { requestFields( fieldWithPath("title").type(JsonFieldType.STRING).description("등록 대상 가게 이름"), fieldWithPath("brn").type(JsonFieldType.STRING).description("사업자 번호"), + fieldWithPath("address").type(JsonFieldType.STRING).description("가게 도로명 주소"), ), responseHeaders(headerWithName("Location").description("생성된 가게 리소스 URI")), ) diff --git a/mealkitary-api/src/test/kotlin/com/mealkitary/shop/web/RegisterShopControllerTest.kt b/mealkitary-api/src/test/kotlin/com/mealkitary/shop/web/RegisterShopControllerTest.kt index f62186a..521da7c 100644 --- a/mealkitary-api/src/test/kotlin/com/mealkitary/shop/web/RegisterShopControllerTest.kt +++ b/mealkitary-api/src/test/kotlin/com/mealkitary/shop/web/RegisterShopControllerTest.kt @@ -15,7 +15,7 @@ class RegisterShopControllerTest : WebIntegrationTestSupport() { fun `api integration test - registerShop`() { every { registerShopUseCase.register(any()) } answers { 1L } - val registerShopWebRequest = RegisterShopWebRequest("집밥뚝딱 안양점", "123-23-12345") + val registerShopWebRequest = RegisterShopWebRequest("집밥뚝딱 안양점", "123-23-12345", "경기도 안양시 동안구 벌말로 40") mvc.perform( MockMvcRequestBuilders.post("/shops") @@ -28,7 +28,7 @@ class RegisterShopControllerTest : WebIntegrationTestSupport() { @Test fun `api integration test - 가게 이름이 누락된 경우 400 에러를 발생한다`() { - val registerShopWebRequest = RegisterShopWebRequest(brn = "123-23-12345") + val registerShopWebRequest = RegisterShopWebRequest(brn = "123-23-12345", address = "경기도 안양시 동안구 벌말로 40") mvc.perform( MockMvcRequestBuilders.post("/shops") @@ -44,7 +44,7 @@ class RegisterShopControllerTest : WebIntegrationTestSupport() { @Test fun `api integration test - 사업자 번호가 누락된 경우 400 에러를 발생한다`() { - val registerShopWebRequest = RegisterShopWebRequest(title = "집밥뚝딱 안양점") + val registerShopWebRequest = RegisterShopWebRequest(title = "집밥뚝딱 안양점", address = "경기도 안양시 동안구 벌말로 40") mvc.perform( MockMvcRequestBuilders.post("/shops") @@ -58,6 +58,22 @@ class RegisterShopControllerTest : WebIntegrationTestSupport() { .andExpect(jsonPath("$..errors[0].reason").value("사업자 번호는 필수입니다.")) } + @Test + fun `api integration test - 주소가 누락된 경우 400 에러를 발생한다`() { + val registerShopWebRequest = RegisterShopWebRequest(title = "집밥뚝딱 안양점", brn = "123-23-12345") + + mvc.perform( + MockMvcRequestBuilders.post("/shops") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(registerShopWebRequest)) + ) + .andExpect(status().isBadRequest) + .andExpect(jsonPath("$.status").value("400")) + .andExpect(jsonPath("$.message").value("잘못된 입력값입니다.")) + .andExpect(jsonPath("$..errors[0].field").value("address")) + .andExpect(jsonPath("$..errors[0].reason").value("주소는 필수입니다.")) + } + @Test fun `api integration test - JSON 형식이 아닌 경우 400 에러가 발생한다`() { mvc.perform( diff --git a/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/port/input/RegisterShopRequest.kt b/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/port/input/RegisterShopRequest.kt index b11e2f1..9598f31 100644 --- a/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/port/input/RegisterShopRequest.kt +++ b/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/port/input/RegisterShopRequest.kt @@ -2,5 +2,6 @@ package com.mealkitary.shop.application.port.input data class RegisterShopRequest( val title: String, - val brn: String + val brn: String, + val address: String ) diff --git a/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/service/RegisterShopService.kt b/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/service/RegisterShopService.kt index 8da3cab..f36d12c 100644 --- a/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/service/RegisterShopService.kt +++ b/mealkitary-application/src/main/kotlin/com/mealkitary/shop/application/service/RegisterShopService.kt @@ -3,23 +3,23 @@ package com.mealkitary.shop.application.service import com.mealkitary.shop.application.port.input.RegisterShopRequest import com.mealkitary.shop.application.port.input.RegisterShopUseCase import com.mealkitary.shop.application.port.output.SaveShopPort -import com.mealkitary.shop.domain.shop.factory.ShopBusinessNumberValidator import com.mealkitary.shop.domain.shop.factory.ShopFactory import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -@Transactional(readOnly = true) +@Transactional class RegisterShopService( private val saveShopPort: SaveShopPort, - shopBusinessNumberValidator: ShopBusinessNumberValidator + private val shopFactory: ShopFactory ) : RegisterShopUseCase { - private val shopFactory = ShopFactory(shopBusinessNumberValidator) - - @Transactional override fun register(registerShopRequest: RegisterShopRequest): Long { - val shop = shopFactory.createOne(registerShopRequest.title, registerShopRequest.brn) + val shop = shopFactory.createOne( + registerShopRequest.title, + registerShopRequest.brn, + registerShopRequest.address + ) return saveShopPort.saveOne(shop) } diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt index 23b9d34..bec01bb 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt @@ -6,6 +6,9 @@ import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle +import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.shop.domain.shop.address.ShopAddress import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.shouldBe import io.mockk.every @@ -24,6 +27,19 @@ class GetShopServiceTest : AnnotationSpec() { ShopTitle.from("집밥뚝딱"), ShopStatus.VALID, ShopBusinessNumber.from("123-45-67890"), + ShopAddress.of( + "1234567890", + Coordinates.of( + 126.99599512792346, + 35.976749396987046 + ), + Address.of( + "region1DepthName", + "region2DepthName", + "region3DepthName", + "region4DepthName" + ) + ), mutableListOf(), mutableListOf() ) diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt index 2e2e6be..73daf7d 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt @@ -2,8 +2,17 @@ package com.mealkitary.shop.application.service import com.mealkitary.shop.application.port.input.RegisterShopRequest import com.mealkitary.shop.application.port.output.SaveShopPort +import com.mealkitary.shop.domain.product.Product import com.mealkitary.shop.domain.shop.Shop +import com.mealkitary.shop.domain.shop.ShopBusinessNumber +import com.mealkitary.shop.domain.shop.ShopStatus +import com.mealkitary.shop.domain.shop.ShopTitle +import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.shop.domain.shop.address.ShopAddress +import com.mealkitary.shop.domain.shop.factory.AddressResolver import com.mealkitary.shop.domain.shop.factory.ShopBusinessNumberValidator +import com.mealkitary.shop.domain.shop.factory.ShopFactory import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.collections.shouldBeEmpty @@ -12,19 +21,36 @@ import io.kotest.matchers.throwable.shouldHaveMessage import io.mockk.every import io.mockk.mockk import io.mockk.slot +import java.time.LocalTime class RegisterShopServiceTest : AnnotationSpec() { private val saveShopPort = mockk() + private val shopFactory = mockk() private val shopBusinessNumberValidator = mockk() - private val registerShopService = RegisterShopService(saveShopPort, shopBusinessNumberValidator) + private val addressResolver = mockk() + private val registerShopService = RegisterShopService(saveShopPort, shopFactory) @Test fun `service unit test - 신규 가게를 등록한다`() { val shopSlot = slot() - val request = RegisterShopRequest("집밥뚝딱 안양점", "123-23-12345") + val request = RegisterShopRequest("집밥뚝딱 안양점", "123-23-12345", "경기도 안양시 동안구 벌말로 40") + val expectedShopAddress = + ShopAddress.of("1234567890", Coordinates.of(0.0, 0.0), Address.of("경기도", "안양시 동안구", "벌말로", "40")) + + val mockedShop = Shop( + ShopTitle.from(request.title), + ShopStatus.VALID, + ShopBusinessNumber.from(request.brn), + expectedShopAddress, + emptyList().toMutableList(), + emptyList().toMutableList() + ) + + every { + shopFactory.createOne(request.title, request.brn, request.address) + } returns mockedShop every { saveShopPort.saveOne(capture(shopSlot)) } answers { 1L } - every { shopBusinessNumberValidator.validate(any()) } answers {} val result = registerShopService.register(request) @@ -32,15 +58,23 @@ class RegisterShopServiceTest : AnnotationSpec() { result shouldBe 1L capturedShop.businessNumber.value shouldBe "123-23-12345" capturedShop.title.value shouldBe "집밥뚝딱 안양점" + capturedShop.address shouldBe expectedShopAddress capturedShop.products.shouldBeEmpty() capturedShop.reservableTimes.shouldBeEmpty() } @Test fun `service unit test - 가게 이름 형식에 맞지 않으면 예외를 발생한다`() { - val request = RegisterShopRequest("invalid!#@", "123-23-12345") + val request = RegisterShopRequest("invalid!#@", "123-23-12345", "경기도 안양시 동안구 벌말로 40") + val expectedShopAddress = + ShopAddress.of("1234567890", Coordinates.of(0.0, 0.0), Address.of("경기도", "안양시 동안구", "벌말로", "40")) + + every { + shopFactory.createOne(any(), any(), any()) + } throws IllegalArgumentException("올바른 가게 이름 형식이 아닙니다.(한글, 영문, 공백, 숫자만 포함 가능)") every { saveShopPort.saveOne(any()) } answers { 1L } every { shopBusinessNumberValidator.validate(any()) } answers {} + every { addressResolver.resolveAddress("경기도 안양시 동안구 벌말로 40") } returns expectedShopAddress shouldThrow { registerShopService.register(request) @@ -49,7 +83,11 @@ class RegisterShopServiceTest : AnnotationSpec() { @Test fun `service unit test - 사업자 번호 형식에 맞지 않으면 예외를 발생한다`() { - val request = RegisterShopRequest("집밥뚝딱 안양점", "invalid-brn") + val request = RegisterShopRequest("집밥뚝딱 안양점", "invalid-brn", "경기도 안양시 동안구 벌말로 40") + + every { + shopFactory.createOne(any(), any(), any()) + } throws IllegalArgumentException("올바른 사업자번호 형식이 아닙니다.") every { saveShopPort.saveOne(any()) } answers { 1L } every { shopBusinessNumberValidator.validate(any()) } answers {} diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt index b755b9a..108f25e 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt @@ -6,6 +6,9 @@ import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle +import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.shop.domain.shop.address.ShopAddress import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.shouldBe @@ -25,6 +28,19 @@ class UpdateShopStatusServiceTest : AnnotationSpec() { ShopTitle.from("제목"), ShopStatus.VALID, ShopBusinessNumber.from("123-12-12345"), + ShopAddress.of( + "1234567890", + Coordinates.of( + 126.99599512792346, + 35.976749396987046 + ), + Address.of( + "region1DepthName", + "region2DepthName", + "region3DepthName", + "region4DepthName" + ) + ), mutableListOf(), mutableListOf() ) @@ -44,6 +60,19 @@ class UpdateShopStatusServiceTest : AnnotationSpec() { ShopTitle.from("제목"), ShopStatus.INVALID, ShopBusinessNumber.from("123-12-12345"), + ShopAddress.of( + "1234567890", + Coordinates.of( + 126.99599512792346, + 35.976749396987046 + ), + Address.of( + "region1DepthName", + "region2DepthName", + "region3DepthName", + "region4DepthName" + ) + ), mutableListOf(), mutableListOf() ) @@ -63,6 +92,19 @@ class UpdateShopStatusServiceTest : AnnotationSpec() { ShopTitle.from("제목"), ShopStatus.VALID, ShopBusinessNumber.from("123-12-12345"), + ShopAddress.of( + "1234567890", + Coordinates.of( + 126.99599512792346, + 35.976749396987046 + ), + Address.of( + "region1DepthName", + "region2DepthName", + "region3DepthName", + "region4DepthName" + ) + ), mutableListOf(), mutableListOf() ) From 362e52ff9e30db584293cc5f7357045a7508c0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 15:00:10 +0900 Subject: [PATCH 13/25] =?UTF-8?q?refactor:=20=EA=B0=80=EA=B2=8C=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20=EC=A3=BC=EC=86=8C=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/shop/domain/shop/Shop.kt | 4 ++ .../shop/domain/shop/address/Address.kt | 34 +++++++++++ .../shop/domain/shop/address/Coordinates.kt | 27 +++++++++ .../shop/domain/shop/address/ShopAddress.kt | 30 ++++++++++ .../shop/domain/shop/AddressTest.kt | 28 +++++++++ .../shop/domain/shop/CoordinatesTest.kt | 31 ++++++++++ .../shop/domain/shop/ShopAddressTest.kt | 60 +++++++++++++++++++ .../testFixtures/kotlin/data/ShopTestData.kt | 24 +++++++- .../src/main/resources/data.sql | 8 +-- 9 files changed, 241 insertions(+), 5 deletions(-) create mode 100644 mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt create mode 100644 mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt create mode 100644 mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt create mode 100644 mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt create mode 100644 mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt create mode 100644 mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/Shop.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/Shop.kt index 79dcbe6..352c3cc 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/Shop.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/Shop.kt @@ -1,6 +1,7 @@ package com.mealkitary.shop.domain.shop import com.mealkitary.shop.domain.product.Product +import com.mealkitary.shop.domain.shop.address.ShopAddress import java.time.LocalDateTime import java.time.LocalTime import javax.persistence.CascadeType @@ -23,6 +24,7 @@ class Shop( title: ShopTitle, status: ShopStatus, businessNumber: ShopBusinessNumber, + address: ShopAddress, reservableTimes: MutableList, products: MutableList ) { @@ -58,6 +60,8 @@ class Shop( val businessNumber: ShopBusinessNumber = businessNumber + val address: ShopAddress = address + fun checkReservableShop() { if (status.isInvalidStatus()) { throw IllegalStateException("유효하지 않은 가게입니다.") diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt new file mode 100644 index 0000000..2cde784 --- /dev/null +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt @@ -0,0 +1,34 @@ +package com.mealkitary.shop.domain.shop.address + +import javax.persistence.Column +import javax.persistence.Embeddable + +@Embeddable +class Address( + @Column(name = "region_1depth_name", nullable = false) + val region1DepthName: String, + @Column(name = "region_2depth_name", nullable = false) + val region2DepthName: String, + @Column(name = "region_3depth_name") + val region3DepthName: String, + @Column(name = "region_4depth_name") + val region4DepthName: String +) { + + companion object { + fun of( + region1DepthName: String, + region2DepthName: String, + region3DepthName: String, + region4DepthName: String + ): Address { + + return Address( + region1DepthName, + region2DepthName, + region3DepthName, + region4DepthName + ) + } + } +} diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt new file mode 100644 index 0000000..c07a374 --- /dev/null +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt @@ -0,0 +1,27 @@ +package com.mealkitary.shop.domain.shop.address + +import javax.persistence.Column +import javax.persistence.Embeddable + +@Embeddable +class Coordinates( + @Column(name = "longitude", nullable = false) + val longitude: Double, + @Column(name = "latitude", nullable = false) + val latitude: Double +) { + + companion object { + fun of(longitude: Double, latitude: Double): Coordinates { + checkIsCoordinate(longitude, latitude) + + return Coordinates(longitude, latitude) + } + + private fun checkIsCoordinate(longitude: Double, latitude: Double) { + if (longitude !in -180.0..180.0 || latitude !in -90.0..90.0) { + throw IllegalArgumentException("유효하지 않은 좌표 범위입니다.") + } + } + } +} diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt new file mode 100644 index 0000000..5cf9e14 --- /dev/null +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt @@ -0,0 +1,30 @@ +package com.mealkitary.shop.domain.shop.address + +import javax.persistence.Column +import javax.persistence.Embeddable +import javax.persistence.Embedded + +@Embeddable +class ShopAddress private constructor( + @Column(name = "city_code", nullable = false) + val cityCode: String, + @Embedded + val coordinates: Coordinates, + @Embedded + val address: Address +) { + + companion object { + fun of(cityCode: String, coordinates: Coordinates, address: Address): ShopAddress { + checkIsCityCodeLength(cityCode) + + return ShopAddress(cityCode, coordinates, address) + } + + private fun checkIsCityCodeLength(cityCode: String) { + if (cityCode.length != 10) { + throw IllegalArgumentException("올바른 지역 코드가 아닙니다. (행정동 지역 코드는 10자리)") + } + } + } +} diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt new file mode 100644 index 0000000..e64d8df --- /dev/null +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt @@ -0,0 +1,28 @@ +package com.mealkitary.shop.domain.shop + +import com.mealkitary.shop.domain.shop.address.Address +import io.kotest.core.spec.style.AnnotationSpec +import io.kotest.matchers.shouldBe + +class AddressTest : AnnotationSpec() { + + @Test + fun `올바른 주소를 입력할 경우 객체를 생성할 수 있다`() { + val region1DepthName = "서울" + val region2DepthName = "강남구" + val region3DepthName = "논현동" + val region4DepthName = "논현로" + + val address = Address.of( + region1DepthName, + region2DepthName, + region3DepthName, + region4DepthName + ) + + address.region1DepthName shouldBe region1DepthName + address.region2DepthName shouldBe region2DepthName + address.region3DepthName shouldBe region3DepthName + address.region4DepthName shouldBe region4DepthName + } +} diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt new file mode 100644 index 0000000..910cae0 --- /dev/null +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt @@ -0,0 +1,31 @@ +package com.mealkitary.shop.domain.shop + +import com.mealkitary.shop.domain.shop.address.Coordinates +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.AnnotationSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.throwable.shouldHaveMessage + +class CoordinatesTest : AnnotationSpec() { + + @Test + fun `범위를 벗어나는 좌표일 경우 예외를 발생한다`() { + val longitude = -188.023 + val latitude = 999.7412 + + shouldThrow { + Coordinates.of(longitude, latitude) + } shouldHaveMessage "유효하지 않은 좌표 범위입니다." + } + + @Test + fun `올바른 좌표를 입력했을 경우 객체를 생성한다`() { + val longitude = -150.653 + val latitude = 46.492 + + val coordinates = Coordinates.of(longitude, latitude) + + coordinates.longitude shouldBe longitude + coordinates.latitude shouldBe latitude + } +} diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt new file mode 100644 index 0000000..512ff4a --- /dev/null +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt @@ -0,0 +1,60 @@ +package com.mealkitary.shop.domain.shop + +import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.shop.domain.shop.address.ShopAddress +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.AnnotationSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.throwable.shouldHaveMessage + +class ShopAddressTest : AnnotationSpec() { + + @Test + fun `올바른 값들을 입력했을 경우 객체를 생성할 수 있다`() { + val cityCode = "1234567890" + val coordinates = Coordinates.of( + -150.653, + 46.492 + ) + val address = Address.of( + "region1DepthName", + "region2DepthName", + "region3DepthName", + "region4DepthName" + ) + + val shopAddress = ShopAddress.of( + cityCode, + coordinates, + address + ) + + shopAddress.cityCode shouldBe cityCode + shopAddress.coordinates shouldBe coordinates + shopAddress.address shouldBe address + } + + @Test + fun `지역 코드가 올바르지 않을 경우 예외를 발생한다`() { + val cityCode = "25231491723109" + val coordinates = Coordinates.of( + -150.653, + 46.492 + ) + val address = Address.of( + "region1DepthName", + "region2DepthName", + "region3DepthName", + "region4DepthName" + ) + + shouldThrow { + ShopAddress.of( + cityCode, + coordinates, + address + ) + } shouldHaveMessage "올바른 지역 코드가 아닙니다. (행정동 지역 코드는 10자리)" + } +} diff --git a/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt b/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt index 1389d2a..7f52f3c 100644 --- a/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt +++ b/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt @@ -5,6 +5,9 @@ import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle +import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.shop.domain.shop.address.ShopAddress import data.ProductTestData.Companion.defaultProduct import java.time.LocalTime @@ -22,7 +25,20 @@ class ShopTestData { defaultProduct().withId(1L).withName("부대찌개").build(), defaultProduct().withId(2L).withName("닭볶음탕").build() ), - private var shopBusinessNumber: ShopBusinessNumber = ShopBusinessNumber.from("123-45-67890") + private var shopBusinessNumber: ShopBusinessNumber = ShopBusinessNumber.from("123-45-67890"), + private var shopAddress: ShopAddress = ShopAddress.of( + "1234567890", + Coordinates.of( + 126.99599512792346, + 35.976749396987046 + ), + Address.of( + "region1DepthName", + "region2DepthName", + "region3DepthName", + "roadName" + ) + ) ) { fun withTitle(title: String): ShopBuilder { @@ -50,11 +66,17 @@ class ShopTestData { return this } + fun withAddress(shopAddress: ShopAddress): ShopBuilder { + this.shopAddress = shopAddress + return this + } + fun build(): Shop { return Shop( ShopTitle.from(this.title), this.shopStatus, this.shopBusinessNumber, + this.shopAddress, this.reservableTimes.toMutableList(), this.products.toMutableList() ) diff --git a/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/main/resources/data.sql b/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/main/resources/data.sql index 929806b..ab9372a 100644 --- a/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/main/resources/data.sql +++ b/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/main/resources/data.sql @@ -1,5 +1,5 @@ insert into shop -values (1, '123-12-12345', 'VALID', '집밥뚝딱 철산점'); +values (1, '경기도', '광명시', '철산동', '철산로', '1234567890', 30.03, 50.05, '123-12-12345', 'VALID', '집밥뚝딱 철산점'); insert into product values (1, '부대찌개', 15800, 1); insert into product @@ -17,7 +17,7 @@ values (1, '18:30'); insert into shop -values (2, '123-12-12345', 'VALID', '집밥뚝딱 안양점'); +values (2, '경기도', '안양시', '동안구', '경수대로', '1234567890', 30.03, 50.05, '123-12-12345', 'VALID', '집밥뚝딱 안양점'); insert into product values (4, '비비고 만두', 3200, 2); insert into product @@ -30,7 +30,7 @@ insert into reservable_time values (2, '19:30'); insert into shop -values (3, '123-12-12345', 'VALID', '집밥뚝딱 숭실대입구점'); +values (3, '서울시', '동작구', '상도동', '', '1234567890', 30.03, 50.05, '123-12-12345', 'VALID', '집밥뚝딱 숭실대입구점'); insert into product values (7, '왕만두', 4900, 3); insert into product @@ -48,7 +48,7 @@ values (3, '23:30'); insert into shop -values (4, '123-12-12345', 'VALID', '집밥뚝딱 다산점'); +values (4, '경기도', '남양주시', '다산동', '', '1234567890', 30.03, 50.05, '123-12-12345', 'VALID', '집밥뚝딱 다산점'); insert into product values (10, '김치찌개', 15800, 4); insert into reservable_time From c096b9a6c47d3f92eb0258b1e4882b80ef2b86c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 15:02:18 +0900 Subject: [PATCH 14/25] =?UTF-8?q?refactor:=20=EB=8F=84=EB=A1=9C=EB=AA=85?= =?UTF-8?q?=20=EC=A3=BC=EC=86=8C=EB=A5=BC=20=EC=A3=BC=EC=86=8C=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EB=A1=9C=20=EB=B3=80=ED=99=98=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/shop/factory/AddressResolver.kt | 8 +++ .../shop/domain/shop/factory/ShopFactory.kt | 11 ++- .../domain/shop/factory/ShopFactoryTest.kt | 48 +++++++++++-- .../address/SimpleAddressResolver.kt | 41 +++++++++++ .../test/kotlin/SimpleAddressResolverTest.kt | 69 +++++++++++++++++++ 5 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/AddressResolver.kt create mode 100644 mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt create mode 100644 mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/AddressResolver.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/AddressResolver.kt new file mode 100644 index 0000000..83c3e12 --- /dev/null +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/AddressResolver.kt @@ -0,0 +1,8 @@ +package com.mealkitary.shop.domain.shop.factory + +import com.mealkitary.shop.domain.shop.address.ShopAddress + +interface AddressResolver { + + fun resolveAddress(address: String): ShopAddress +} diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt index 76cc4df..da6efee 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt @@ -5,21 +5,28 @@ import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle +import com.mealkitary.shop.domain.shop.address.ShopAddress +import org.springframework.stereotype.Component import java.time.LocalTime +@Component class ShopFactory( - private val shopBusinessNumberValidator: ShopBusinessNumberValidator + private val shopBusinessNumberValidator: ShopBusinessNumberValidator, + private val addressResolver: AddressResolver ) { - fun createOne(title: String, brn: String): Shop { + fun createOne(title: String, brn: String, address: String): Shop { val shopBusinessNumber = ShopBusinessNumber.from(brn) + val shopAddress: ShopAddress = addressResolver.resolveAddress(address) + shopBusinessNumberValidator.validate(shopBusinessNumber) return Shop( ShopTitle.from(title), ShopStatus.VALID, shopBusinessNumber, + shopAddress, emptyList().toMutableList(), emptyList().toMutableList(), ) diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt index 34a8382..b700838 100644 --- a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt @@ -1,5 +1,8 @@ package com.mealkitary.shop.domain.shop.factory +import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.shop.domain.shop.address.ShopAddress import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.shouldBe @@ -10,31 +13,66 @@ import io.mockk.mockk class ShopFactoryTest : AnnotationSpec() { private val shopBusinessNumberValidator = mockk() - private val shopFactory = ShopFactory(shopBusinessNumberValidator) + private val addressResolver = mockk() + private val shopFactory = ShopFactory(shopBusinessNumberValidator, addressResolver) @Test fun `사업자번호가 유효하지 않으면 예외를 발생한다`() { shouldThrow { - shopFactory.createOne("집밥뚝딱 안양점", "32-12-3221") + shopFactory.createOne("집밥뚝딱 안양점", "32-12-3221", "경기도 안양시 동안구 벌말로 40") } shouldHaveMessage "올바른 사업자번호 형식이 아닙니다." } @Test - fun `실제로 유효한 사업자번호와 가게이름이라면 가게를 생성한다`() { + fun `실제로 유효한 사업자번호와 가게이름, 주소라면 가게를 생성한다`() { + val expectedShopAddress = + ShopAddress.of("1234567890", Coordinates.of(0.0, 0.0), Address.of("경기도", "안양시 동안구", "벌말로", "40")) + every { shopBusinessNumberValidator.validate(any()) } answers { } + every { addressResolver.resolveAddress("경기도 안양시 동안구 벌말로 40") } returns expectedShopAddress - val shop = shopFactory.createOne("집밥뚝딱 안양점", "321-23-12345") + val shop = shopFactory.createOne("집밥뚝딱 안양점", "321-23-12345", "경기도 안양시 동안구 벌말로 40") shop.title.value shouldBe "집밥뚝딱 안양점" shop.businessNumber.value shouldBe "321-23-12345" + shop.address shouldBe expectedShopAddress } @Test fun `가게 이름이 유효하지 않으면 예외를 발생한다`() { + val expectedShopAddress = + ShopAddress.of("1234567890", Coordinates.of(0.0, 0.0), Address.of("경기도", "안양시 동안구", "벌말로", "40")) + + every { shopBusinessNumberValidator.validate(any()) } answers { } + every { addressResolver.resolveAddress("경기도 안양시 동안구 벌말로 40") } returns expectedShopAddress + + shouldThrow { + shopFactory.createOne("집밥뚝딱 ! 안양점", "321-23-12345", "경기도 안양시 동안구 벌말로 40") + } shouldHaveMessage "올바른 가게 이름 형식이 아닙니다.(한글, 영문, 공백, 숫자만 포함 가능)" + } + + @Test + fun `도로명 주소를 받아 주소 객체를 생선한다`() { + val address = "경기도 안양시 동안구 벌말로" + val shopAddress = ShopAddress.of( + "1234567890", + Coordinates.of( + 127.0, + 40.0 + ), + Address.of( + "경기도", + "안양시", + "동안구", + "벌말로" + ) + ) + every { shopBusinessNumberValidator.validate(any()) } answers { } + every { addressResolver.resolveAddress(address) } answers { shopAddress } shouldThrow { - shopFactory.createOne("집밥뚝딱 ! 안양점", "321-23-12345") + shopFactory.createOne("집밥뚝딱 ! 안양점", "321-23-12345", "경기도 안양시 동안구 벌말로 40") } shouldHaveMessage "올바른 가게 이름 형식이 아닙니다.(한글, 영문, 공백, 숫자만 포함 가능)" } } diff --git a/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt b/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt new file mode 100644 index 0000000..b6c0cfc --- /dev/null +++ b/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt @@ -0,0 +1,41 @@ +package com.mealkitary.address + +import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.shop.domain.shop.address.ShopAddress +import com.mealkitary.shop.domain.shop.factory.AddressResolver +import org.springframework.stereotype.Component + +private const val ADDRESS_MIN_LENGTH = 2 + +@Component +class SimpleAddressResolver : AddressResolver { + + override fun resolveAddress(address: String): ShopAddress { + val value = address.split(" ") + + if (value.size < ADDRESS_MIN_LENGTH) { + throw IllegalArgumentException("주소 형식이 올바르지 않습니다.") + } + + val region1DepthName = value[0] + val region2DepthName = value[1] + val region3DepthName = value.getOrNull(2) ?: "" + val region4DepthName = value.getOrNull(3) ?: "" + + // TODO: 좌표 및 지역 코드를 카카오 API에서 받아올 예정 + return ShopAddress.of( + "1234567890", + Coordinates.of( + 127.0, + 40.0 + ), + Address.of( + region1DepthName, + region2DepthName, + region3DepthName, + region4DepthName + ) + ) + } +} diff --git a/mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt b/mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt new file mode 100644 index 0000000..bed0715 --- /dev/null +++ b/mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt @@ -0,0 +1,69 @@ +package com.mealkitary.address + +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.AnnotationSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.throwable.shouldHaveMessage +import org.springframework.stereotype.Component + +@Component +class SimpleAddressResolverTest : AnnotationSpec() { + + @Test + fun `adapter unit test - 문자열 주소값을 받아 주소 객체를 생성한다`() { + val address = "서울특별시 강남구 역삼동 논현로" + val resolver = SimpleAddressResolver() + + val shopAddress = resolver.resolveAddress(address) + + shopAddress.cityCode shouldBe "1234567890" + shopAddress.coordinates.longitude shouldBe 127.0 + shopAddress.coordinates.latitude shouldBe 40.0 + shopAddress.address.region1DepthName shouldBe "서울특별시" + shopAddress.address.region2DepthName shouldBe "강남구" + shopAddress.address.region3DepthName shouldBe "역삼동" + shopAddress.address.region4DepthName shouldBe "논현로" + } + + @Test + fun `adapter unit test - 문자열 주소값이 3등분일 경우 3개의 정보를 가진 주소 객체를 생성한다`() { + val address = "경기도 남양주시 다산동" + val resolver = SimpleAddressResolver() + + val shopAddress = resolver.resolveAddress(address) + + shopAddress.cityCode shouldBe "1234567890" + shopAddress.coordinates.longitude shouldBe 127.0 + shopAddress.coordinates.latitude shouldBe 40.0 + shopAddress.address.region1DepthName shouldBe "경기도" + shopAddress.address.region2DepthName shouldBe "남양주시" + shopAddress.address.region3DepthName shouldBe "다산동" + shopAddress.address.region4DepthName shouldBe "" + } + + @Test + fun `adapter unit test - 문자열 주소값이 2등분일 경우 2개의 정보를 가진 주소 객체를 생성한다`() { + val address = "제주특별자치도 한림읍" + val resolver = SimpleAddressResolver() + + val shopAddress = resolver.resolveAddress(address) + + shopAddress.cityCode shouldBe "1234567890" + shopAddress.coordinates.longitude shouldBe 127.0 + shopAddress.coordinates.latitude shouldBe 40.0 + shopAddress.address.region1DepthName shouldBe "제주특별자치도" + shopAddress.address.region2DepthName shouldBe "한림읍" + shopAddress.address.region3DepthName shouldBe "" + shopAddress.address.region4DepthName shouldBe "" + } + + @Test + fun `adapter unit test - 문자열 주소값이 2등분 이하일 경우 예외를 발생한다`() { + val address = "제주특별자치도" + val resolver = SimpleAddressResolver() + + shouldThrow { + resolver.resolveAddress(address) + } shouldHaveMessage "주소 형식이 올바르지 않습니다." + } +} From 534af9cf03455e7f3582c78946b00ab7ff79fe7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 15:04:34 +0900 Subject: [PATCH 15/25] =?UTF-8?q?chore:=20=EC=A3=BC=EC=86=8C=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=EA=B8=B0=20=EB=AA=A8=EB=93=88=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/mealkitary-main-develop-ci.yml | 4 +++- .github/workflows/mealkitary-test-coverage-automation.yml | 5 ++++- mealkitary-api/build.gradle.kts | 1 + .../adapter-address-resolver/build.gradle.kts | 8 ++++++++ settings.gradle.kts | 5 ++++- 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 mealkitary-infrastructure/adapter-address-resolver/build.gradle.kts diff --git a/.github/workflows/mealkitary-main-develop-ci.yml b/.github/workflows/mealkitary-main-develop-ci.yml index 901d7f2..cdfd207 100644 --- a/.github/workflows/mealkitary-main-develop-ci.yml +++ b/.github/workflows/mealkitary-main-develop-ci.yml @@ -55,6 +55,7 @@ jobs: ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-firebase-notification/build/test-results/**/*.xml ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/test-results/**/*.xml + ./mealkitary-infrastructure/adapter-address-resolver/build/test-results/**/*.xml - name: Jacoco Coverage 리포트 전송 uses: codecov/codecov-action@v3 @@ -67,7 +68,8 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-firebase-notification/build/reports/jacoco/test/jacocoTestReport.xml, - ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml + ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml, + ./mealkitary-infrastructure/adapter-address-resolver/build/reports/jacoco/test/jacocoTestReport.xml, name: mealkitary-codecov verbose: true diff --git a/.github/workflows/mealkitary-test-coverage-automation.yml b/.github/workflows/mealkitary-test-coverage-automation.yml index acd71d2..e25282a 100644 --- a/.github/workflows/mealkitary-test-coverage-automation.yml +++ b/.github/workflows/mealkitary-test-coverage-automation.yml @@ -43,6 +43,7 @@ jobs: ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/test-results/**/*.xml ./mealkitary-infrastructure/adapter-firebase-notification/build/test-results/**/*.xml ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/test-results/**/*.xml + ./mealkitary-infrastructure/adapter-address-resolver/build/test-results/**/*.xml - name: Jacoco Coverage 리포트 전송 uses: codecov/codecov-action@v3 @@ -55,6 +56,8 @@ jobs: ./mealkitary-infrastructure/adapter-persistence-spring-data-jpa/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-firebase-notification/build/reports/jacoco/test/jacocoTestReport.xml, - ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml + ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml, + ./mealkitary-infrastructure/adapter-address-resolver/build/reports/jacoco/test/jacocoTestReport.xml + name: mealkitary-codecov verbose: true diff --git a/mealkitary-api/build.gradle.kts b/mealkitary-api/build.gradle.kts index 5ffe9a6..6426857 100644 --- a/mealkitary-api/build.gradle.kts +++ b/mealkitary-api/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { implementation(project(":mealkitary-infrastructure:adapter-persistence-spring-data-jpa")) implementation(project(":mealkitary-infrastructure:adapter-paymentgateway-tosspayments")) implementation(project(":mealkitary-infrastructure:adapter-firebase-notification")) + implementation(project(":mealkitary-infrastructure:adapter-address-resolver")) implementation( project( ":mealkitary-infrastructure:business-registration-number-validator:adapter-open-api-brn-validator", diff --git a/mealkitary-infrastructure/adapter-address-resolver/build.gradle.kts b/mealkitary-infrastructure/adapter-address-resolver/build.gradle.kts new file mode 100644 index 0000000..2f0606e --- /dev/null +++ b/mealkitary-infrastructure/adapter-address-resolver/build.gradle.kts @@ -0,0 +1,8 @@ +dependencies { + val querydslVersion: String by properties + implementation("com.querydsl:querydsl-jpa:$querydslVersion") + implementation("com.h2database:h2") + implementation(project(":mealkitary-domain")) + implementation(project(":mealkitary-application")) + testImplementation(testFixtures(project(":mealkitary-domain"))) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 52db22b..680a318 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,7 +8,8 @@ include( "mealkitary-infrastructure:adapter-paymentgateway-tosspayments", "mealkitary-infrastructure:adapter-firebase-notification", "mealkitary-infrastructure:business-registration-number-validator:adapter-open-api-brn-validator", - "mealkitary-infrastructure:business-registration-number-validator:adapter-simple-brn-validator" + "mealkitary-infrastructure:business-registration-number-validator:adapter-simple-brn-validator", + "mealkitary-infrastructure:adapter-address-resolver" ) pluginManagement { @@ -36,3 +37,5 @@ pluginManagement { } } } +include("mealkitary-infrastructure:adapter-address-resolver") +findProject(":mealkitary-infrastructure:adapter-address-resolver")?.name = "adapter-address-resolver" From b5b20982c56ae168e36c6928de556d15a0b5afc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 16:16:29 +0900 Subject: [PATCH 16/25] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/shop/domain/shop/factory/ShopFactory.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt index da6efee..0c80427 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt @@ -6,10 +6,8 @@ import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle import com.mealkitary.shop.domain.shop.address.ShopAddress -import org.springframework.stereotype.Component import java.time.LocalTime -@Component class ShopFactory( private val shopBusinessNumberValidator: ShopBusinessNumberValidator, private val addressResolver: AddressResolver From d85a9e20f6a124f0b5fde131ec2a6783aedf0ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 16:17:19 +0900 Subject: [PATCH 17/25] =?UTF-8?q?fix:=20=ED=8C=8C=EC=9D=BC=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EB=AC=B8=EC=A0=9C=EB=A5=BC=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?build.gradle=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mealkitary-api/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/mealkitary-api/build.gradle.kts b/mealkitary-api/build.gradle.kts index 6426857..c0ec197 100644 --- a/mealkitary-api/build.gradle.kts +++ b/mealkitary-api/build.gradle.kts @@ -6,6 +6,7 @@ val snippetsDir by extra { file("build/generated-snippets") } val asciidoctorExt: Configuration by configurations.creating bootJar.enabled = true +bootJar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE jar.enabled = false plugins { From c6e148fc44f29bc86cba45a5abb60047bdc52826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 16:43:42 +0900 Subject: [PATCH 18/25] =?UTF-8?q?refactor:=20=EC=A3=BC=EC=86=8C=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/application/service/GetShopServiceTest.kt | 2 +- .../application/service/UpdateShopStatusServiceTest.kt | 6 +++--- .../com/mealkitary/shop/domain/shop/address/Address.kt | 8 ++++---- .../kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt | 6 +++--- .../com/mealkitary/shop/domain/shop/ShopAddressTest.kt | 4 ++-- .../com/mealkitary/address/SimpleAddressResolver.kt | 4 ++-- .../src/test/kotlin/SimpleAddressResolverTest.kt | 6 +++--- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt index bec01bb..73eec59 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt @@ -37,7 +37,7 @@ class GetShopServiceTest : AnnotationSpec() { "region1DepthName", "region2DepthName", "region3DepthName", - "region4DepthName" + "roadName" ) ), mutableListOf(), diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt index 108f25e..4881a16 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt @@ -38,7 +38,7 @@ class UpdateShopStatusServiceTest : AnnotationSpec() { "region1DepthName", "region2DepthName", "region3DepthName", - "region4DepthName" + "roadName" ) ), mutableListOf(), @@ -70,7 +70,7 @@ class UpdateShopStatusServiceTest : AnnotationSpec() { "region1DepthName", "region2DepthName", "region3DepthName", - "region4DepthName" + "roadName" ) ), mutableListOf(), @@ -102,7 +102,7 @@ class UpdateShopStatusServiceTest : AnnotationSpec() { "region1DepthName", "region2DepthName", "region3DepthName", - "region4DepthName" + "roadName" ) ), mutableListOf(), diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt index 2cde784..3e89fd8 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt @@ -11,8 +11,8 @@ class Address( val region2DepthName: String, @Column(name = "region_3depth_name") val region3DepthName: String, - @Column(name = "region_4depth_name") - val region4DepthName: String + @Column(name = "road_name") + val roadName: String ) { companion object { @@ -20,14 +20,14 @@ class Address( region1DepthName: String, region2DepthName: String, region3DepthName: String, - region4DepthName: String + roadName: String ): Address { return Address( region1DepthName, region2DepthName, region3DepthName, - region4DepthName + roadName ) } } diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt index e64d8df..3a84bb7 100644 --- a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt @@ -11,18 +11,18 @@ class AddressTest : AnnotationSpec() { val region1DepthName = "서울" val region2DepthName = "강남구" val region3DepthName = "논현동" - val region4DepthName = "논현로" + val roadName = "논현로" val address = Address.of( region1DepthName, region2DepthName, region3DepthName, - region4DepthName + roadName ) address.region1DepthName shouldBe region1DepthName address.region2DepthName shouldBe region2DepthName address.region3DepthName shouldBe region3DepthName - address.region4DepthName shouldBe region4DepthName + address.roadName shouldBe roadName } } diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt index 512ff4a..9047495 100644 --- a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt @@ -21,7 +21,7 @@ class ShopAddressTest : AnnotationSpec() { "region1DepthName", "region2DepthName", "region3DepthName", - "region4DepthName" + "roadName" ) val shopAddress = ShopAddress.of( @@ -46,7 +46,7 @@ class ShopAddressTest : AnnotationSpec() { "region1DepthName", "region2DepthName", "region3DepthName", - "region4DepthName" + "roadName" ) shouldThrow { diff --git a/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt b/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt index b6c0cfc..c3aa189 100644 --- a/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt +++ b/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt @@ -21,7 +21,7 @@ class SimpleAddressResolver : AddressResolver { val region1DepthName = value[0] val region2DepthName = value[1] val region3DepthName = value.getOrNull(2) ?: "" - val region4DepthName = value.getOrNull(3) ?: "" + val roadName = value.getOrNull(3) ?: "" // TODO: 좌표 및 지역 코드를 카카오 API에서 받아올 예정 return ShopAddress.of( @@ -34,7 +34,7 @@ class SimpleAddressResolver : AddressResolver { region1DepthName, region2DepthName, region3DepthName, - region4DepthName + roadName ) ) } diff --git a/mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt b/mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt index bed0715..79a6e3e 100644 --- a/mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt +++ b/mealkitary-infrastructure/adapter-address-resolver/src/test/kotlin/SimpleAddressResolverTest.kt @@ -22,7 +22,7 @@ class SimpleAddressResolverTest : AnnotationSpec() { shopAddress.address.region1DepthName shouldBe "서울특별시" shopAddress.address.region2DepthName shouldBe "강남구" shopAddress.address.region3DepthName shouldBe "역삼동" - shopAddress.address.region4DepthName shouldBe "논현로" + shopAddress.address.roadName shouldBe "논현로" } @Test @@ -38,7 +38,7 @@ class SimpleAddressResolverTest : AnnotationSpec() { shopAddress.address.region1DepthName shouldBe "경기도" shopAddress.address.region2DepthName shouldBe "남양주시" shopAddress.address.region3DepthName shouldBe "다산동" - shopAddress.address.region4DepthName shouldBe "" + shopAddress.address.roadName shouldBe "" } @Test @@ -54,7 +54,7 @@ class SimpleAddressResolverTest : AnnotationSpec() { shopAddress.address.region1DepthName shouldBe "제주특별자치도" shopAddress.address.region2DepthName shouldBe "한림읍" shopAddress.address.region3DepthName shouldBe "" - shopAddress.address.region4DepthName shouldBe "" + shopAddress.address.roadName shouldBe "" } @Test From a8e12ce30aa7a6ab2fc2f22b90a0185a0c81e20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 16:52:24 +0900 Subject: [PATCH 19/25] =?UTF-8?q?refactor:=20=EC=A7=80=EC=97=AD=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EA=B8=B8=EC=9D=B4=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/shop/domain/shop/address/ShopAddress.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt index 5cf9e14..c74a16f 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt @@ -4,6 +4,8 @@ import javax.persistence.Column import javax.persistence.Embeddable import javax.persistence.Embedded +private const val CITY_CODE_LENGTH = 10 + @Embeddable class ShopAddress private constructor( @Column(name = "city_code", nullable = false) @@ -22,7 +24,7 @@ class ShopAddress private constructor( } private fun checkIsCityCodeLength(cityCode: String) { - if (cityCode.length != 10) { + if (cityCode.length != CITY_CODE_LENGTH) { throw IllegalArgumentException("올바른 지역 코드가 아닙니다. (행정동 지역 코드는 10자리)") } } From 4d21a4fd4d84977980a09818f57a9ee39be8f000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 3 Oct 2023 16:54:49 +0900 Subject: [PATCH 20/25] =?UTF-8?q?refactor:=20=EC=A2=8C=ED=91=9C=20?= =?UTF-8?q?=EB=B2=94=EC=9C=84=20=EA=B2=80=EC=A6=9D=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/shop/domain/shop/address/Coordinates.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt index c07a374..db32f9a 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt @@ -13,12 +13,12 @@ class Coordinates( companion object { fun of(longitude: Double, latitude: Double): Coordinates { - checkIsCoordinate(longitude, latitude) + checkIsCoordinateRange(longitude, latitude) return Coordinates(longitude, latitude) } - private fun checkIsCoordinate(longitude: Double, latitude: Double) { + private fun checkIsCoordinateRange(longitude: Double, latitude: Double) { if (longitude !in -180.0..180.0 || latitude !in -90.0..90.0) { throw IllegalArgumentException("유효하지 않은 좌표 범위입니다.") } From a11411f494b013af6afe9b8ca8623fedcba352c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 4 Oct 2023 01:31:50 +0900 Subject: [PATCH 21/25] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=A4=EB=A7=88=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/mealkitary-main-develop-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mealkitary-main-develop-ci.yml b/.github/workflows/mealkitary-main-develop-ci.yml index cdfd207..8b85b57 100644 --- a/.github/workflows/mealkitary-main-develop-ci.yml +++ b/.github/workflows/mealkitary-main-develop-ci.yml @@ -69,7 +69,7 @@ jobs: ./mealkitary-infrastructure/adapter-paymentgateway-tosspayments/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/adapter-firebase-notification/build/reports/jacoco/test/jacocoTestReport.xml, ./mealkitary-infrastructure/business-registration-number-validator/adapter-simple-brn-validator/build/reports/jacoco/test/jacocoTestReport.xml, - ./mealkitary-infrastructure/adapter-address-resolver/build/reports/jacoco/test/jacocoTestReport.xml, + ./mealkitary-infrastructure/adapter-address-resolver/build/reports/jacoco/test/jacocoTestReport.xml name: mealkitary-codecov verbose: true From b72b1c8de2f573119cc9a5db79a8e89e56501297 Mon Sep 17 00:00:00 2001 From: le2sky Date: Wed, 4 Oct 2023 01:46:27 +0900 Subject: [PATCH 22/25] =?UTF-8?q?refactor=20:=20=EC=9D=98=EB=AF=B8?= =?UTF-8?q?=EA=B0=80=20=EB=93=9C=EB=9F=AC=EB=82=98=EB=8A=94=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9C=BC=EB=A1=9C=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt index a837ac9..25acef2 100644 --- a/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt +++ b/mealkitary-infrastructure/adapter-business-registration-number-validator/open-api-brn-validator/src/main/kotlin/com/mealkitary/brn/OpenApiBrnValidator.kt @@ -34,8 +34,8 @@ class OpenApiBrnValidator( } private fun checkBrnStatus(openApiBrnStatusResponse: OpenApiBrnStatusResponse) { - val result = openApiBrnStatusResponse.data[0] - if (result.b_stt != "계속사업자") { + val openApiBrnStatus = openApiBrnStatusResponse.data[0] + if (openApiBrnStatus.b_stt != "계속사업자") { throw IllegalArgumentException("유효하지 않은 사업자 번호입니다.") } } From 828ec4cb4366e4ae625bbd79dde49c84851e26af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Thu, 5 Oct 2023 03:16:31 +0900 Subject: [PATCH 23/25] =?UTF-8?q?chore:=20=EC=A3=BC=EC=86=8C,=20=EC=A2=8C?= =?UTF-8?q?=ED=91=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mealkitary/shop/application/service/GetShopServiceTest.kt | 4 ++-- .../shop/application/service/RegisterShopServiceTest.kt | 4 ++-- .../shop/application/service/UpdateShopStatusServiceTest.kt | 4 ++-- .../{shop/domain/shop/address => common/model}/Address.kt | 4 ++-- .../{shop/domain/shop/address => common/model}/Coordinates.kt | 2 +- .../com/mealkitary/shop/domain/shop/address/ShopAddress.kt | 2 ++ .../kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt | 2 +- .../kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt | 2 +- .../kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt | 4 ++-- .../mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt | 4 ++-- .../src/testFixtures/kotlin/data/ShopTestData.kt | 4 ++-- .../kotlin/com/mealkitary/address/SimpleAddressResolver.kt | 4 ++-- 12 files changed, 21 insertions(+), 19 deletions(-) rename mealkitary-domain/src/main/kotlin/com/mealkitary/{shop/domain/shop/address => common/model}/Address.kt (91%) rename mealkitary-domain/src/main/kotlin/com/mealkitary/{shop/domain/shop/address => common/model}/Coordinates.kt (93%) diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt index 73eec59..90f93eb 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/GetShopServiceTest.kt @@ -1,13 +1,13 @@ package com.mealkitary.shop.application.service +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import com.mealkitary.shop.application.port.input.ShopResponse import com.mealkitary.shop.application.port.output.LoadShopPort import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle -import com.mealkitary.shop.domain.shop.address.Address -import com.mealkitary.shop.domain.shop.address.Coordinates import com.mealkitary.shop.domain.shop.address.ShopAddress import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.shouldBe diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt index 73daf7d..e61ca1c 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/RegisterShopServiceTest.kt @@ -1,5 +1,7 @@ package com.mealkitary.shop.application.service +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import com.mealkitary.shop.application.port.input.RegisterShopRequest import com.mealkitary.shop.application.port.output.SaveShopPort import com.mealkitary.shop.domain.product.Product @@ -7,8 +9,6 @@ import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle -import com.mealkitary.shop.domain.shop.address.Address -import com.mealkitary.shop.domain.shop.address.Coordinates import com.mealkitary.shop.domain.shop.address.ShopAddress import com.mealkitary.shop.domain.shop.factory.AddressResolver import com.mealkitary.shop.domain.shop.factory.ShopBusinessNumberValidator diff --git a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt index 4881a16..d8e47f7 100644 --- a/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt +++ b/mealkitary-application/src/test/kotlin/com/mealkitary/shop/application/service/UpdateShopStatusServiceTest.kt @@ -1,13 +1,13 @@ package com.mealkitary.shop.application.service +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import com.mealkitary.shop.application.port.output.CheckExistenceShopPort import com.mealkitary.shop.application.port.output.LoadShopPort import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle -import com.mealkitary.shop.domain.shop.address.Address -import com.mealkitary.shop.domain.shop.address.Coordinates import com.mealkitary.shop.domain.shop.address.ShopAddress import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.AnnotationSpec diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/common/model/Address.kt similarity index 91% rename from mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt rename to mealkitary-domain/src/main/kotlin/com/mealkitary/common/model/Address.kt index 3e89fd8..099d9d3 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Address.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/common/model/Address.kt @@ -1,10 +1,10 @@ -package com.mealkitary.shop.domain.shop.address +package com.mealkitary.common.model import javax.persistence.Column import javax.persistence.Embeddable @Embeddable -class Address( +class Address private constructor( @Column(name = "region_1depth_name", nullable = false) val region1DepthName: String, @Column(name = "region_2depth_name", nullable = false) diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/common/model/Coordinates.kt similarity index 93% rename from mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt rename to mealkitary-domain/src/main/kotlin/com/mealkitary/common/model/Coordinates.kt index db32f9a..d11bd0f 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/Coordinates.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/common/model/Coordinates.kt @@ -1,4 +1,4 @@ -package com.mealkitary.shop.domain.shop.address +package com.mealkitary.common.model import javax.persistence.Column import javax.persistence.Embeddable diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt index c74a16f..2229f42 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/address/ShopAddress.kt @@ -1,5 +1,7 @@ package com.mealkitary.shop.domain.shop.address +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import javax.persistence.Column import javax.persistence.Embeddable import javax.persistence.Embedded diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt index 3a84bb7..2c26e06 100644 --- a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/AddressTest.kt @@ -1,6 +1,6 @@ package com.mealkitary.shop.domain.shop -import com.mealkitary.shop.domain.shop.address.Address +import com.mealkitary.common.model.Address import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.shouldBe diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt index 910cae0..970576a 100644 --- a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/CoordinatesTest.kt @@ -1,6 +1,6 @@ package com.mealkitary.shop.domain.shop -import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.common.model.Coordinates import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.shouldBe diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt index 9047495..d490ebd 100644 --- a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/ShopAddressTest.kt @@ -1,7 +1,7 @@ package com.mealkitary.shop.domain.shop -import com.mealkitary.shop.domain.shop.address.Address -import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import com.mealkitary.shop.domain.shop.address.ShopAddress import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.AnnotationSpec diff --git a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt index b700838..709e531 100644 --- a/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt +++ b/mealkitary-domain/src/test/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactoryTest.kt @@ -1,7 +1,7 @@ package com.mealkitary.shop.domain.shop.factory -import com.mealkitary.shop.domain.shop.address.Address -import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import com.mealkitary.shop.domain.shop.address.ShopAddress import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.AnnotationSpec diff --git a/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt b/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt index 7f52f3c..968438f 100644 --- a/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt +++ b/mealkitary-domain/src/testFixtures/kotlin/data/ShopTestData.kt @@ -1,12 +1,12 @@ package data +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import com.mealkitary.shop.domain.product.Product import com.mealkitary.shop.domain.shop.Shop import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle -import com.mealkitary.shop.domain.shop.address.Address -import com.mealkitary.shop.domain.shop.address.Coordinates import com.mealkitary.shop.domain.shop.address.ShopAddress import data.ProductTestData.Companion.defaultProduct import java.time.LocalTime diff --git a/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt b/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt index c3aa189..f15e509 100644 --- a/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt +++ b/mealkitary-infrastructure/adapter-address-resolver/src/main/kotlin/com/mealkitary/address/SimpleAddressResolver.kt @@ -1,7 +1,7 @@ package com.mealkitary.address -import com.mealkitary.shop.domain.shop.address.Address -import com.mealkitary.shop.domain.shop.address.Coordinates +import com.mealkitary.common.model.Address +import com.mealkitary.common.model.Coordinates import com.mealkitary.shop.domain.shop.address.ShopAddress import com.mealkitary.shop.domain.shop.factory.AddressResolver import org.springframework.stereotype.Component From 65a2a07b8ec70178debfa54e901af19decf1ef12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Thu, 5 Oct 2023 03:18:26 +0900 Subject: [PATCH 24/25] =?UTF-8?q?refactor:=20=EB=88=84=EB=9D=BD=EB=90=9C?= =?UTF-8?q?=20`@Component`=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/shop/domain/shop/factory/ShopFactory.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt index 0c80427..da6efee 100644 --- a/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt +++ b/mealkitary-domain/src/main/kotlin/com/mealkitary/shop/domain/shop/factory/ShopFactory.kt @@ -6,8 +6,10 @@ import com.mealkitary.shop.domain.shop.ShopBusinessNumber import com.mealkitary.shop.domain.shop.ShopStatus import com.mealkitary.shop.domain.shop.ShopTitle import com.mealkitary.shop.domain.shop.address.ShopAddress +import org.springframework.stereotype.Component import java.time.LocalTime +@Component class ShopFactory( private val shopBusinessNumberValidator: ShopBusinessNumberValidator, private val addressResolver: AddressResolver From 621ebd70feb23968fd90426dc8c22857fbdb142f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Thu, 5 Oct 2023 03:22:52 +0900 Subject: [PATCH 25/25] =?UTF-8?q?fix:=20=EC=BB=B4=ED=8F=AC=EB=84=8C?= =?UTF-8?q?=ED=8A=B8=20=EC=8A=A4=EC=BA=94=20=EB=AF=B8=EC=A0=81=EC=9A=A9=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mealkitary/PersistenceIntegrationTestSupport.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/test/kotlin/com/mealkitary/PersistenceIntegrationTestSupport.kt b/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/test/kotlin/com/mealkitary/PersistenceIntegrationTestSupport.kt index f6b6d25..1bdfea1 100644 --- a/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/test/kotlin/com/mealkitary/PersistenceIntegrationTestSupport.kt +++ b/mealkitary-infrastructure/adapter-persistence-spring-data-jpa/src/test/kotlin/com/mealkitary/PersistenceIntegrationTestSupport.kt @@ -4,6 +4,7 @@ import com.mealkitary.reservation.application.service.AcceptReservationService import com.mealkitary.reservation.application.service.PayReservationService import com.mealkitary.reservation.application.service.RejectReservationService import com.mealkitary.shop.application.service.RegisterShopService +import com.mealkitary.shop.domain.shop.factory.ShopFactory import com.ninjasquad.springmockk.MockkBean import io.kotest.core.spec.style.AnnotationSpec import io.kotest.extensions.spring.SpringExtension @@ -36,4 +37,7 @@ abstract class PersistenceIntegrationTestSupport : AnnotationSpec() { @MockkBean private lateinit var registerShopService: RegisterShopService + + @MockkBean + private lateinit var shopFactory: ShopFactory }