Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 플랜 도메인 퍼샤드를 통한 유스케이스 통합 리팩토링 #105

Merged
merged 6 commits into from
Jan 16, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,35 @@ data class AddPlanInput(
val categories: List<String>,
)

data class AddPlanOutput(
val planId: Long,
)

@Service
class AddPlanUseCase(
private val planStorageGateway: PlanStorageGateway,
) : UseCase<AddPlanInput, Unit> {
) : UseCase<AddPlanInput, AddPlanOutput> {
@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)
}
}
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Long>,
val categories: List<String>,
) {
fun toCommand(userId: Long): AddPlanInput =
AddPlanInput(
userId = userId,
title = title,
description = description,
primaryRegion = primaryRegion,
secondaryRegion = secondaryRegion,
visitDate = visitDate,
placeIds = placeIds,
categories = categories,
)
}
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -10,4 +11,20 @@ data class UpdatePlanRequest(
val visitDate: LocalDate,
val placeIds: List<Long>,
val categories: List<String>,
)
) {
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,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kr.wooco.woocobe.plan.ui.web.controller.response

data class CreatePlanResponse(
val id: Long,
)

This file was deleted.

This file was deleted.

Loading
Loading