From 8903958889b2e8d430b1d939d2a72d45cfed7f6a Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Tue, 14 Jan 2025 14:07:01 +0900 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=20=ED=94=8C=EB=9E=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=9A=94=EC=B2=AD=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/request/AddPlanRequest.kt | 13 ---------- .../controller/request/CreatePlanRequest.kt | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) delete mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/AddPlanRequest.kt create mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/CreatePlanRequest.kt diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/AddPlanRequest.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/AddPlanRequest.kt deleted file mode 100644 index a455c86c..00000000 --- a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/AddPlanRequest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package kr.wooco.woocobe.plan.ui.web.controller.request - -import java.time.LocalDate - -data class AddPlanRequest( - val title: String, - val description: String, - val primaryRegion: String, - val secondaryRegion: String, - val visitDate: LocalDate, - val placeIds: List, - val categories: List, -) diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/CreatePlanRequest.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/CreatePlanRequest.kt new file mode 100644 index 00000000..62ffeafc --- /dev/null +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/CreatePlanRequest.kt @@ -0,0 +1,26 @@ +package kr.wooco.woocobe.plan.ui.web.controller.request + +import kr.wooco.woocobe.plan.domain.usecase.AddPlanInput +import java.time.LocalDate + +data class CreatePlanRequest( + val title: String, + val description: String, + val primaryRegion: String, + val secondaryRegion: String, + val visitDate: LocalDate, + val placeIds: List, + val categories: List, +) { + fun toCommand(userId: Long): AddPlanInput = + AddPlanInput( + userId = userId, + title = title, + description = description, + primaryRegion = primaryRegion, + secondaryRegion = secondaryRegion, + visitDate = visitDate, + placeIds = placeIds, + categories = categories, + ) +} From eb522e9d63f4615c0c7a325e03441eafd118872a Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Tue, 14 Jan 2025 14:07:45 +0900 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20=ED=94=8C=EB=9E=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=9A=94=EC=B2=AD=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/request/UpdatePlanRequest.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/UpdatePlanRequest.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/UpdatePlanRequest.kt index 5b7ba9cc..8e9a7715 100644 --- a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/UpdatePlanRequest.kt +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/request/UpdatePlanRequest.kt @@ -1,5 +1,6 @@ package kr.wooco.woocobe.plan.ui.web.controller.request +import kr.wooco.woocobe.plan.domain.usecase.UpdatePlanInput import java.time.LocalDate data class UpdatePlanRequest( @@ -10,4 +11,20 @@ data class UpdatePlanRequest( val visitDate: LocalDate, val placeIds: List, val categories: List, -) +) { + fun toCommand( + userId: Long, + planId: Long, + ): UpdatePlanInput = + UpdatePlanInput( + userId = userId, + planId = planId, + title = title, + description = description, + primaryRegion = primaryRegion, + secondaryRegion = secondaryRegion, + visitDate = visitDate, + placeIds = placeIds, + categories = categories, + ) +} From aefd2a2d7fd8c3afc7e8de5ae21854bfd052b119 Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Tue, 14 Jan 2025 14:08:45 +0900 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20=ED=94=8C=EB=9E=9C=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC=20=EB=B0=8F=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/response/GetAllPlanResponse.kt | 34 -------- .../controller/response/GetPlanResponse.kt | 32 -------- .../controller/response/PlanDetailResponse.kt | 82 +++++++++++++++++++ 3 files changed, 82 insertions(+), 66 deletions(-) delete mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetAllPlanResponse.kt delete mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetPlanResponse.kt create mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/PlanDetailResponse.kt diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetAllPlanResponse.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetAllPlanResponse.kt deleted file mode 100644 index 556dfdf1..00000000 --- a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetAllPlanResponse.kt +++ /dev/null @@ -1,34 +0,0 @@ -package kr.wooco.woocobe.plan.ui.web.controller.response - -import kr.wooco.woocobe.plan.domain.model.PlanPlace -import kr.wooco.woocobe.plan.domain.usecase.GetAllPlanOutput -import java.time.LocalDate - -data class GetAllPlanResponse( - val plans: List, -) { - companion object { - fun from(getAllPlanOutput: GetAllPlanOutput): GetAllPlanResponse = - GetAllPlanResponse( - getAllPlanOutput.plans.map { plan -> - SimplePlanResponse( - planId = plan.id, - title = plan.title, - primaryRegion = plan.region.primaryRegion, - secondaryRegion = plan.region.secondaryRegion, - visitDate = plan.visitDate, - places = plan.places, - ) - }, - ) - } -} - -data class SimplePlanResponse( - val planId: Long, - val title: String, - val primaryRegion: String, - val secondaryRegion: String, - val visitDate: LocalDate, - val places: List, -) diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetPlanResponse.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetPlanResponse.kt deleted file mode 100644 index af73391e..00000000 --- a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/GetPlanResponse.kt +++ /dev/null @@ -1,32 +0,0 @@ -package kr.wooco.woocobe.plan.ui.web.controller.response - -import kr.wooco.woocobe.plan.domain.model.PlanPlace -import kr.wooco.woocobe.plan.domain.usecase.GetPlanOutput -import java.time.LocalDate - -data class GetPlanResponse( - val planId: Long, - val title: String, - val description: String, - val primaryRegion: String, - val secondaryRegion: String, - val visitDate: LocalDate, - val places: List, - val categories: List, -) { - companion object { - fun from(getPlanOutput: GetPlanOutput) = - with(getPlanOutput) { - GetPlanResponse( - planId = plan.id, - title = plan.title, - description = plan.description, - primaryRegion = plan.region.primaryRegion, - secondaryRegion = plan.region.secondaryRegion, - visitDate = plan.visitDate, - places = plan.places, - categories = plan.categories.map { it.name }, - ) - } - } -} diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/PlanDetailResponse.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/PlanDetailResponse.kt new file mode 100644 index 00000000..5852a4c9 --- /dev/null +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/PlanDetailResponse.kt @@ -0,0 +1,82 @@ +package kr.wooco.woocobe.plan.ui.web.controller.response + +import kr.wooco.woocobe.place.domain.model.Place +import kr.wooco.woocobe.plan.domain.model.Plan +import java.time.LocalDate + +data class PlanDetailResponse( + val id: Long, + val title: String, + val description: String, + val primaryRegion: String, + val secondaryRegion: String, + val visitDate: LocalDate, + val places: List, + val categories: List, +) { + companion object { + fun of( + plan: Plan, + places: List, + ): PlanDetailResponse { + val placeMap = places.associateBy { it.id } + return fromPlan(plan, placeMap) + } + + fun listOf( + plans: List, + places: List, + ): List { + val placeMap = places.associateBy { it.id } + return plans.map { plan -> fromPlan(plan, placeMap) } + } + + private fun fromPlan( + plan: Plan, + placeMap: Map, + ): PlanDetailResponse = + PlanDetailResponse( + id = plan.id, + title = plan.title, + description = plan.description, + primaryRegion = plan.region.primaryRegion, + secondaryRegion = plan.region.secondaryRegion, + visitDate = plan.visitDate, + places = plan.places.map { planPlace -> + val place = requireNotNull(placeMap[planPlace.placeId]) + PlanPlaceResponse.of(planPlace.order, place) + }, + categories = plan.categories.map { it.name }, + ) + } +} + +data class PlanPlaceResponse( + val order: Int, + val id: Long, + val name: String, + val latitude: Double, + val longitude: Double, + val address: String, + val kakaoMapPlaceId: String, + val averageRating: Double, + val reviewCount: Long, +) { + companion object { + fun of( + order: Int, + place: Place, + ): PlanPlaceResponse = + PlanPlaceResponse( + order = order, + id = place.id, + name = place.name, + latitude = place.latitude, + longitude = place.longitude, + address = place.address, + kakaoMapPlaceId = place.kakaoMapPlaceId, + averageRating = place.averageRating, + reviewCount = place.reviewCount, + ) + } +} From 8760f851de02765fe892232717e7c93c94dfc735 Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:09:43 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=ED=94=8C=EB=9E=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=20=EC=9D=91=EB=8B=B5=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/domain/usecase/AddPlanUseCase.kt | 31 ++++++++++++------- .../controller/response/CreatePlanResponse.kt | 5 +++ 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/CreatePlanResponse.kt diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/domain/usecase/AddPlanUseCase.kt b/src/main/kotlin/kr/wooco/woocobe/plan/domain/usecase/AddPlanUseCase.kt index d5aa580c..b7366b8f 100644 --- a/src/main/kotlin/kr/wooco/woocobe/plan/domain/usecase/AddPlanUseCase.kt +++ b/src/main/kotlin/kr/wooco/woocobe/plan/domain/usecase/AddPlanUseCase.kt @@ -19,26 +19,35 @@ data class AddPlanInput( val categories: List, ) +data class AddPlanOutput( + val planId: Long, +) + @Service class AddPlanUseCase( private val planStorageGateway: PlanStorageGateway, -) : UseCase { +) : UseCase { @Transactional - override fun execute(input: AddPlanInput) { + override fun execute(input: AddPlanInput): AddPlanOutput { val region = PlanRegion( primaryRegion = input.primaryRegion, secondaryRegion = input.secondaryRegion, ) - val plan = Plan.register( - userId = input.userId, - title = input.title, - description = input.description, - region = region, - visitDate = input.visitDate, - placeIds = input.placeIds, - categories = input.categories, + val plan = planStorageGateway.save( + Plan.register( + userId = input.userId, + title = input.title, + description = input.description, + region = region, + visitDate = input.visitDate, + placeIds = input.placeIds, + categories = input.categories, + ), + ) + + return AddPlanOutput( + planId = plan.id, ) - planStorageGateway.save(plan) } } diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/CreatePlanResponse.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/CreatePlanResponse.kt new file mode 100644 index 00000000..9b0c9975 --- /dev/null +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/response/CreatePlanResponse.kt @@ -0,0 +1,5 @@ +package kr.wooco.woocobe.plan.ui.web.controller.response + +data class CreatePlanResponse( + val id: Long, +) From 2dbedc5a75f846221f3aac3e3a053bca64cc2ef8 Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:10:13 +0900 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20=ED=94=8C=EB=9E=9C=20=ED=8D=BC?= =?UTF-8?q?=EC=83=A4=EB=93=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=BB=A4?= =?UTF-8?q?=EB=A7=A8=EB=93=9C=20=EB=B0=8F=20=EC=A1=B0=ED=9A=8C=20=ED=8D=BC?= =?UTF-8?q?=EC=83=A4=EB=93=9C=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/ui/web/facade/PlanCommandFacade.kt | 36 +++++++++++++++ .../plan/ui/web/facade/PlanFacadeService.kt | 8 ---- .../plan/ui/web/facade/PlanQueryFacade.kt | 44 +++++++++++++++++++ 3 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanCommandFacade.kt delete mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanFacadeService.kt create mode 100644 src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanQueryFacade.kt diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanCommandFacade.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanCommandFacade.kt new file mode 100644 index 00000000..18a50079 --- /dev/null +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanCommandFacade.kt @@ -0,0 +1,36 @@ +package kr.wooco.woocobe.plan.ui.web.facade + +import kr.wooco.woocobe.plan.domain.usecase.AddPlanUseCase +import kr.wooco.woocobe.plan.domain.usecase.DeletePlanInput +import kr.wooco.woocobe.plan.domain.usecase.DeletePlanUseCase +import kr.wooco.woocobe.plan.domain.usecase.UpdatePlanUseCase +import kr.wooco.woocobe.plan.ui.web.controller.request.CreatePlanRequest +import kr.wooco.woocobe.plan.ui.web.controller.request.UpdatePlanRequest +import kr.wooco.woocobe.plan.ui.web.controller.response.CreatePlanResponse +import org.springframework.stereotype.Service + +@Service +class PlanCommandFacade( + private val addPlanUseCase: AddPlanUseCase, + private val updatePlanUseCase: UpdatePlanUseCase, + private val deletePlanUseCase: DeletePlanUseCase, +) { + fun createPlan( + userId: Long, + request: CreatePlanRequest, + ): CreatePlanResponse { + val addPlanResult = addPlanUseCase.execute(request.toCommand(userId)) + return CreatePlanResponse(addPlanResult.planId) + } + + fun updatePlan( + userId: Long, + planId: Long, + request: UpdatePlanRequest, + ) = updatePlanUseCase.execute(request.toCommand(userId = userId, planId = planId)) + + fun deletePlan( + userId: Long, + planId: Long, + ) = deletePlanUseCase.execute(DeletePlanInput(userId = userId, planId = planId)) +} diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanFacadeService.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanFacadeService.kt deleted file mode 100644 index ed3665ad..00000000 --- a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanFacadeService.kt +++ /dev/null @@ -1,8 +0,0 @@ -package kr.wooco.woocobe.plan.ui.web.facade - -import org.springframework.stereotype.Service - -// TODO : 구현 - -@Service -class PlanFacadeService diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanQueryFacade.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanQueryFacade.kt new file mode 100644 index 00000000..2d21540a --- /dev/null +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/facade/PlanQueryFacade.kt @@ -0,0 +1,44 @@ +package kr.wooco.woocobe.plan.ui.web.facade + +import kr.wooco.woocobe.place.domain.usecase.GetAllPlaceInput +import kr.wooco.woocobe.place.domain.usecase.GetAllPlaceUseCase +import kr.wooco.woocobe.plan.domain.usecase.GetAllPlanInput +import kr.wooco.woocobe.plan.domain.usecase.GetAllPlanUseCase +import kr.wooco.woocobe.plan.domain.usecase.GetPlanInput +import kr.wooco.woocobe.plan.domain.usecase.GetPlanUseCase +import kr.wooco.woocobe.plan.ui.web.controller.response.PlanDetailResponse +import org.springframework.stereotype.Service + +@Service +class PlanQueryFacade( + private val getPlanUseCase: GetPlanUseCase, + private val getAllPlanUseCase: GetAllPlanUseCase, + private val getAllPlaceUseCase: GetAllPlaceUseCase, +) { + fun getPlanDetail( + userId: Long, + planId: Long, + ): PlanDetailResponse { + val getPlanResult = getPlanUseCase.execute(GetPlanInput(userId = userId, planId = planId)) + + val placeIds = getPlanResult.plan.places.map { it.placeId } + val getAllPlaceResult = getAllPlaceUseCase.execute(GetAllPlaceInput(placeIds = placeIds)) + + return PlanDetailResponse.of( + plan = getPlanResult.plan, + places = getAllPlaceResult.places, + ) + } + + fun getAllPlanDetail(userId: Long): List { + val getAllPlanResult = getAllPlanUseCase.execute(GetAllPlanInput(userId = userId)) + + val placeIds = getAllPlanResult.plans.flatMap { it.places }.map { it.placeId } + val getAllPlaceResult = getAllPlaceUseCase.execute(GetAllPlaceInput(placeIds = placeIds)) + + return PlanDetailResponse.listOf( + plans = getAllPlanResult.plans, + places = getAllPlaceResult.places, + ) + } +} From e262e88c5d03d5111cbc97728bfa33a53c87b5bc Mon Sep 17 00:00:00 2001 From: jspark <98972385+JunseoParKK@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:10:57 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat:=20=ED=94=8C=EB=9E=9C=20api=20?= =?UTF-8?q?=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EC=84=A4=EC=A0=95=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=B6=94=EA=B0=80=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../woocobe/plan/ui/web/controller/PlanApi.kt | 44 ++++++++- .../plan/ui/web/controller/PlanController.kt | 99 ++++++------------- 2 files changed, 74 insertions(+), 69 deletions(-) diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanApi.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanApi.kt index fb0c2eb2..9e0ac885 100644 --- a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanApi.kt +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanApi.kt @@ -1,5 +1,45 @@ package kr.wooco.woocobe.plan.ui.web.controller -// TODO: 구현 - 스웨거용 인터페이스 +import io.swagger.v3.oas.annotations.security.SecurityRequirement +import io.swagger.v3.oas.annotations.tags.Tag +import kr.wooco.woocobe.plan.ui.web.controller.request.CreatePlanRequest +import kr.wooco.woocobe.plan.ui.web.controller.request.UpdatePlanRequest +import kr.wooco.woocobe.plan.ui.web.controller.response.CreatePlanResponse +import kr.wooco.woocobe.plan.ui.web.controller.response.PlanDetailResponse +import org.springframework.http.ResponseEntity +import org.springframework.security.core.annotation.AuthenticationPrincipal +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestBody -interface PlanApi +@Tag(name = "플랜 API") +interface PlanApi { + @SecurityRequirement(name = "JWT") + fun getPlanDetail( + @AuthenticationPrincipal userId: Long, + @PathVariable planId: Long, + ): ResponseEntity + + @SecurityRequirement(name = "JWT") + fun getAllPlanDetail( + @AuthenticationPrincipal userId: Long, + ): ResponseEntity> + + @SecurityRequirement(name = "JWT") + fun createPlan( + @AuthenticationPrincipal userId: Long, + @RequestBody request: CreatePlanRequest, + ): ResponseEntity + + @SecurityRequirement(name = "JWT") + fun updatePlan( + @AuthenticationPrincipal userId: Long, + @RequestBody request: UpdatePlanRequest, + @PathVariable planId: Long, + ): ResponseEntity + + @SecurityRequirement(name = "JWT") + fun deletePlan( + @AuthenticationPrincipal userId: Long, + @PathVariable planId: Long, + ): ResponseEntity +} diff --git a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanController.kt b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanController.kt index 82c3187c..aaea1f2c 100644 --- a/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanController.kt +++ b/src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanController.kt @@ -1,19 +1,11 @@ package kr.wooco.woocobe.plan.ui.web.controller -import kr.wooco.woocobe.plan.domain.usecase.AddPlanInput -import kr.wooco.woocobe.plan.domain.usecase.AddPlanUseCase -import kr.wooco.woocobe.plan.domain.usecase.DeletePlanInput -import kr.wooco.woocobe.plan.domain.usecase.DeletePlanUseCase -import kr.wooco.woocobe.plan.domain.usecase.GetAllPlanInput -import kr.wooco.woocobe.plan.domain.usecase.GetAllPlanUseCase -import kr.wooco.woocobe.plan.domain.usecase.GetPlanInput -import kr.wooco.woocobe.plan.domain.usecase.GetPlanUseCase -import kr.wooco.woocobe.plan.domain.usecase.UpdatePlanInput -import kr.wooco.woocobe.plan.domain.usecase.UpdatePlanUseCase -import kr.wooco.woocobe.plan.ui.web.controller.request.AddPlanRequest +import kr.wooco.woocobe.plan.ui.web.controller.request.CreatePlanRequest import kr.wooco.woocobe.plan.ui.web.controller.request.UpdatePlanRequest -import kr.wooco.woocobe.plan.ui.web.controller.response.GetAllPlanResponse -import kr.wooco.woocobe.plan.ui.web.controller.response.GetPlanResponse +import kr.wooco.woocobe.plan.ui.web.controller.response.CreatePlanResponse +import kr.wooco.woocobe.plan.ui.web.controller.response.PlanDetailResponse +import kr.wooco.woocobe.plan.ui.web.facade.PlanCommandFacade +import kr.wooco.woocobe.plan.ui.web.facade.PlanQueryFacade import org.springframework.http.ResponseEntity import org.springframework.security.core.annotation.AuthenticationPrincipal import org.springframework.web.bind.annotation.DeleteMapping @@ -28,90 +20,63 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/api/v1/plans") class PlanController( - private val addPlanUseCase: AddPlanUseCase, - private val getAllPlanUseCase: GetAllPlanUseCase, - private val getPlanUseCase: GetPlanUseCase, - private val updatePlanUseCase: UpdatePlanUseCase, - private val deletePlanUseCase: DeletePlanUseCase, -) { + private val planQueryFacade: PlanQueryFacade, + private val planCommandFacade: PlanCommandFacade, +) : PlanApi { @PostMapping - fun createPlan( + override fun createPlan( @AuthenticationPrincipal userId: Long, - @RequestBody request: AddPlanRequest, - ): ResponseEntity { - addPlanUseCase.execute( - AddPlanInput( - userId = userId, - title = request.title, - description = request.description, - primaryRegion = request.primaryRegion, - secondaryRegion = request.secondaryRegion, - visitDate = request.visitDate, - placeIds = request.placeIds, - categories = request.categories, - ), + @RequestBody request: CreatePlanRequest, + ): ResponseEntity { + val response = planCommandFacade.createPlan( + userId = userId, + request = request, ) - return ResponseEntity.ok().build() + return ResponseEntity.ok(response) } @GetMapping - fun getAllPlans( + override fun getAllPlanDetail( @AuthenticationPrincipal userId: Long, - ): ResponseEntity { - val response = GetAllPlanResponse.from( - getAllPlanUseCase.execute(GetAllPlanInput(userId)), - ) + ): ResponseEntity> { + val response = planQueryFacade.getAllPlanDetail(userId) return ResponseEntity.ok(response) } @GetMapping("/{planId}") - fun getPlan( + override fun getPlanDetail( @AuthenticationPrincipal userId: Long, @PathVariable planId: Long, - ): ResponseEntity { - val response = GetPlanResponse.from( - getPlanUseCase.execute( - GetPlanInput( - userId = userId, - planId = planId, - ), - ), + ): ResponseEntity { + val response = planQueryFacade.getPlanDetail( + userId = userId, + planId = planId, ) return ResponseEntity.ok(response) } @PatchMapping("/{planId}") - fun updatePlan( + override fun updatePlan( @AuthenticationPrincipal userId: Long, @RequestBody request: UpdatePlanRequest, @PathVariable planId: Long, ): ResponseEntity { - updatePlanUseCase.execute( - UpdatePlanInput( - userId = userId, - planId = planId, - title = request.title, - description = request.description, - primaryRegion = request.primaryRegion, - secondaryRegion = request.secondaryRegion, - visitDate = request.visitDate, - placeIds = request.placeIds, - categories = request.categories, - ), + planCommandFacade.updatePlan( + userId = userId, + planId = planId, + request = request, ) return ResponseEntity.ok().build() } @DeleteMapping("/{planId}") - fun deletePlan( + override fun deletePlan( @AuthenticationPrincipal userId: Long, @PathVariable planId: Long, ): ResponseEntity { - deletePlanUseCase.execute( - DeletePlanInput( - userId = userId, - planId = planId, - ), + planCommandFacade.deletePlan( + userId = userId, + planId = planId, ) return ResponseEntity.ok().build() }