From b4cb5356147edf6a574032088548fa7c0fd7ee16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=98=81=EA=B8=B8?= Date: Mon, 23 Sep 2024 20:51:44 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=A0=88=EC=9D=B4=EC=96=B4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DestinationApplicationService.kt | 29 ------------------- .../destination/DestinationController.kt | 26 +++++++++++++++-- 2 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 withaeng-api/src/main/kotlin/com/withaeng/api/applicationservice/destination/DestinationApplicationService.kt diff --git a/withaeng-api/src/main/kotlin/com/withaeng/api/applicationservice/destination/DestinationApplicationService.kt b/withaeng-api/src/main/kotlin/com/withaeng/api/applicationservice/destination/DestinationApplicationService.kt deleted file mode 100644 index 2421079..0000000 --- a/withaeng-api/src/main/kotlin/com/withaeng/api/applicationservice/destination/DestinationApplicationService.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.withaeng.api.applicationservice.destination - -import com.withaeng.api.applicationservice.accompany.dto.DestinationResponse -import com.withaeng.domain.destination.City -import com.withaeng.domain.destination.Continent -import com.withaeng.domain.destination.Country -import org.springframework.stereotype.Service -import java.util.* - -@Service -class DestinationApplicationService { - - fun getDestinations(): DestinationResponse { - val structure = EnumMap>>(Continent::class.java) - Continent.entries.forEach { continent -> - val countriesInContinent = EnumMap>(Country::class.java) - Country.entries - .filter { it.continentCode == continent.continentCode } - .forEach { country -> - val citiesInCountry = City.entries - .filter { it.countryCode == country.countryCode } - .toList() - countriesInContinent[country] = citiesInCountry - } - structure[continent] = countriesInContinent - } - return DestinationResponse(structure) - } -} \ No newline at end of file diff --git a/withaeng-api/src/main/kotlin/com/withaeng/api/controller/destination/DestinationController.kt b/withaeng-api/src/main/kotlin/com/withaeng/api/controller/destination/DestinationController.kt index 0cd200d..e4bfa4b 100644 --- a/withaeng-api/src/main/kotlin/com/withaeng/api/controller/destination/DestinationController.kt +++ b/withaeng-api/src/main/kotlin/com/withaeng/api/controller/destination/DestinationController.kt @@ -1,22 +1,42 @@ package com.withaeng.api.controller.destination import com.withaeng.api.applicationservice.accompany.dto.DestinationResponse -import com.withaeng.api.applicationservice.destination.DestinationApplicationService import com.withaeng.api.common.ApiResponse +import com.withaeng.domain.destination.City +import com.withaeng.domain.destination.Continent +import com.withaeng.domain.destination.Country import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import java.util.* @Tag(name = "Destination", description = "여행지 API") @RestController @RequestMapping("/api/v1/destinations") -class DestinationController(private val destinationApplicationService: DestinationApplicationService) { +class DestinationController { @GetMapping fun getDestinations(): ApiResponse { return ApiResponse.success( - destinationApplicationService.getDestinations() + DestinationResponse(createDestinationsMap()) ) } + + private fun createDestinationsMap(): EnumMap>> { + val structure = EnumMap>>(Continent::class.java) + Continent.entries.forEach { continent -> + val countriesInContinent = EnumMap>(Country::class.java) + Country.entries + .filter { it.continentCode == continent.continentCode } + .forEach { country -> + val citiesInCountry = City.entries + .filter { it.countryCode == country.countryCode } + .toList() + countriesInContinent[country] = citiesInCountry + } + structure[continent] = countriesInContinent + } + return structure + } } \ No newline at end of file