generated from pricelees/issue-pr-template
refactor: sealed class 도입 및 중복 코드 제거
This commit is contained in:
parent
74ebf9b841
commit
695983bb8b
@ -22,7 +22,7 @@ class DemoController(
|
||||
|
||||
@PostMapping("/wrapper")
|
||||
fun wrapper(
|
||||
@RequestBody @Valid request: WrapperRequest
|
||||
@RequestBody @Valid request: DemoRequest.WrapperRequest
|
||||
): ResponseEntity<Void> {
|
||||
demoService.doSomething(request)
|
||||
|
||||
@ -31,7 +31,7 @@ class DemoController(
|
||||
|
||||
@PostMapping("/primitive")
|
||||
fun primitive(
|
||||
@RequestBody @Valid request: PrimitiveRequest
|
||||
@RequestBody @Valid request: DemoRequest.PrimitiveRequest
|
||||
): ResponseEntity<Void> {
|
||||
demoService.doSomething(request)
|
||||
|
||||
|
||||
@ -3,19 +3,23 @@ package com.sangdol.validation
|
||||
import jakarta.validation.constraints.NotNull
|
||||
|
||||
|
||||
data class WrapperRequest(
|
||||
@NotNull
|
||||
val withAnnotation: String,
|
||||
sealed class DemoRequest {
|
||||
|
||||
val withoutAnnotation: String
|
||||
)
|
||||
abstract val withAnnotation: Any
|
||||
abstract val withoutAnnotation: Any
|
||||
|
||||
data class PrimitiveRequest(
|
||||
@NotNull
|
||||
val withAnnotation: Int,
|
||||
data class WrapperRequest(
|
||||
@NotNull
|
||||
override val withAnnotation: String,
|
||||
override val withoutAnnotation: String
|
||||
) : DemoRequest()
|
||||
|
||||
val withoutAnnotation: Int
|
||||
)
|
||||
data class PrimitiveRequest(
|
||||
@NotNull
|
||||
override val withAnnotation: Int,
|
||||
override val withoutAnnotation: Int
|
||||
) : DemoRequest()
|
||||
}
|
||||
|
||||
data class SolutionForPrimitive(
|
||||
@NotNull
|
||||
|
||||
@ -14,13 +14,8 @@ class DemoService(
|
||||
request.value?.let { log.info { "value: ${request.value}" } }
|
||||
}
|
||||
|
||||
fun doSomething(request: WrapperRequest) {
|
||||
fun doSomething(request: DemoRequest) {
|
||||
log.info { "wrapper requests: $request." }
|
||||
log.info { "withAnnotation: ${request.withAnnotation}, withoutAnnotation: ${request.withoutAnnotation}" }
|
||||
}
|
||||
|
||||
fun doSomething(request: PrimitiveRequest) {
|
||||
log.info { "primitive requests: $request." }
|
||||
log.info { "withAnnotation: ${request.withAnnotation}, withoutAnnotation: ${request.withoutAnnotation}" }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user