Skip to content

Commit

Permalink
feat: 플랜 api 스웨거 설정 정보 추가 (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
junseoparkk committed Jan 16, 2025
1 parent 2dbedc5 commit e262e88
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 69 deletions.
44 changes: 42 additions & 2 deletions src/main/kotlin/kr/wooco/woocobe/plan/ui/web/controller/PlanApi.kt
Original file line number Diff line number Diff line change
@@ -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<PlanDetailResponse>

@SecurityRequirement(name = "JWT")
fun getAllPlanDetail(
@AuthenticationPrincipal userId: Long,
): ResponseEntity<List<PlanDetailResponse>>

@SecurityRequirement(name = "JWT")
fun createPlan(
@AuthenticationPrincipal userId: Long,
@RequestBody request: CreatePlanRequest,
): ResponseEntity<CreatePlanResponse>

@SecurityRequirement(name = "JWT")
fun updatePlan(
@AuthenticationPrincipal userId: Long,
@RequestBody request: UpdatePlanRequest,
@PathVariable planId: Long,
): ResponseEntity<Unit>

@SecurityRequirement(name = "JWT")
fun deletePlan(
@AuthenticationPrincipal userId: Long,
@PathVariable planId: Long,
): ResponseEntity<Unit>
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Unit> {
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<CreatePlanResponse> {
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<GetAllPlanResponse> {
val response = GetAllPlanResponse.from(
getAllPlanUseCase.execute(GetAllPlanInput(userId)),
)
): ResponseEntity<List<PlanDetailResponse>> {
val response = planQueryFacade.getAllPlanDetail(userId)
return ResponseEntity.ok(response)
}

@GetMapping("/{planId}")
fun getPlan(
override fun getPlanDetail(
@AuthenticationPrincipal userId: Long,
@PathVariable planId: Long,
): ResponseEntity<GetPlanResponse> {
val response = GetPlanResponse.from(
getPlanUseCase.execute(
GetPlanInput(
userId = userId,
planId = planId,
),
),
): ResponseEntity<PlanDetailResponse> {
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<Unit> {
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<Unit> {
deletePlanUseCase.execute(
DeletePlanInput(
userId = userId,
planId = planId,
),
planCommandFacade.deletePlan(
userId = userId,
planId = planId,
)
return ResponseEntity.ok().build()
}
Expand Down

0 comments on commit e262e88

Please sign in to comment.