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")
|
@PostMapping("/wrapper")
|
||||||
fun wrapper(
|
fun wrapper(
|
||||||
@RequestBody @Valid request: WrapperRequest
|
@RequestBody @Valid request: DemoRequest.WrapperRequest
|
||||||
): ResponseEntity<Void> {
|
): ResponseEntity<Void> {
|
||||||
demoService.doSomething(request)
|
demoService.doSomething(request)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ class DemoController(
|
|||||||
|
|
||||||
@PostMapping("/primitive")
|
@PostMapping("/primitive")
|
||||||
fun primitive(
|
fun primitive(
|
||||||
@RequestBody @Valid request: PrimitiveRequest
|
@RequestBody @Valid request: DemoRequest.PrimitiveRequest
|
||||||
): ResponseEntity<Void> {
|
): ResponseEntity<Void> {
|
||||||
demoService.doSomething(request)
|
demoService.doSomething(request)
|
||||||
|
|
||||||
|
|||||||
@ -3,19 +3,23 @@ package com.sangdol.validation
|
|||||||
import jakarta.validation.constraints.NotNull
|
import jakarta.validation.constraints.NotNull
|
||||||
|
|
||||||
|
|
||||||
data class WrapperRequest(
|
sealed class DemoRequest {
|
||||||
|
|
||||||
|
abstract val withAnnotation: Any
|
||||||
|
abstract val withoutAnnotation: Any
|
||||||
|
|
||||||
|
data class WrapperRequest(
|
||||||
@NotNull
|
@NotNull
|
||||||
val withAnnotation: String,
|
override val withAnnotation: String,
|
||||||
|
override val withoutAnnotation: String
|
||||||
|
) : DemoRequest()
|
||||||
|
|
||||||
val withoutAnnotation: String
|
data class PrimitiveRequest(
|
||||||
)
|
|
||||||
|
|
||||||
data class PrimitiveRequest(
|
|
||||||
@NotNull
|
@NotNull
|
||||||
val withAnnotation: Int,
|
override val withAnnotation: Int,
|
||||||
|
override val withoutAnnotation: Int
|
||||||
val withoutAnnotation: Int
|
) : DemoRequest()
|
||||||
)
|
}
|
||||||
|
|
||||||
data class SolutionForPrimitive(
|
data class SolutionForPrimitive(
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@ -14,13 +14,8 @@ class DemoService(
|
|||||||
request.value?.let { log.info { "value: ${request.value}" } }
|
request.value?.let { log.info { "value: ${request.value}" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doSomething(request: WrapperRequest) {
|
fun doSomething(request: DemoRequest) {
|
||||||
log.info { "wrapper requests: $request." }
|
log.info { "wrapper requests: $request." }
|
||||||
log.info { "withAnnotation: ${request.withAnnotation}, withoutAnnotation: ${request.withoutAnnotation}" }
|
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