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] =?UTF-8?q?feat:=20=ED=94=8C=EB=9E=9C=20api=20=EC=8A=A4?= =?UTF-8?q?=EC=9B=A8=EA=B1=B0=20=EC=84=A4=EC=A0=95=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=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 fb0c2eb..9e0ac88 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 82c3187..aaea1f2 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() }