File tree Expand file tree Collapse file tree 4 files changed +13
-9
lines changed
apis/src/main/kotlin/org/yapp/apis/book
global-utils/src/main/kotlin/org/yapp/globalutils/util Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package org.yapp.apis.book.controller
33import jakarta.validation.Valid
44import org.springframework.http.ResponseEntity
55import org.springframework.web.bind.annotation.GetMapping
6+ import org.springframework.web.bind.annotation.ModelAttribute
67import org.springframework.web.bind.annotation.RequestMapping
78import org.springframework.web.bind.annotation.RestController
89import org.yapp.apis.book.dto.request.BookDetailRequest
@@ -19,14 +20,14 @@ class BookController(
1920) : BookControllerApi {
2021
2122 @GetMapping(" /search" )
22- override fun searchBooks (@Valid request : BookSearchRequest ): ResponseEntity <BookSearchResponse > {
23+ override fun searchBooks (@Valid @ModelAttribute request : BookSearchRequest ): ResponseEntity <BookSearchResponse > {
2324 val response = bookUseCase.searchBooks(request)
2425 return ResponseEntity .ok(response)
2526 }
2627
2728 @GetMapping(" /detail" )
2829 override fun getBookDetail (
29- @Valid request : BookDetailRequest
30+ @Valid @ModelAttribute request : BookDetailRequest
3031 ): ResponseEntity <BookDetailResponse > {
3132 val response = bookUseCase.getBookDetail(request)
3233 return ResponseEntity .ok(response)
Original file line number Diff line number Diff line change 11package org.yapp.apis.book.dto.request
22
33import jakarta.validation.constraints.NotBlank
4+ import jakarta.validation.constraints.Pattern // Pattern 어노테이션 추가
5+ import org.yapp.globalutils.util.RegexUtils
46import org.yapp.infra.external.aladin.dto.AladinBookLookupRequest
57
68data class BookDetailRequest private constructor(
79 @field:NotBlank(message = "아이템 ID 는 필수입니다.")
10+ @field:Pattern(
11+ regexp = RegexUtils .NOT_BLANK_AND_NOT_NULL_STRING_PATTERN ,
12+ message = "아이템 ID 는 유효한 ISBN 형식이 아닙니다."
13+ )
814 val itemId : String? = null ,
915 val itemIdType : String? = " ISBN" ,
1016 val optResult : List <String >? = null
1117) {
1218 fun toAladinRequest (): AladinBookLookupRequest {
13- require(! itemId.isNullOrBlank()) { " 아이템 ID는 비어있을 수 없습니다." }
1419 return AladinBookLookupRequest .create(
15- itemId = this .itemId,
20+ itemId = this .itemId!! ,
1621 itemIdType = this .itemIdType ? : " ISBN" ,
1722 optResult = this .optResult
1823 )
Original file line number Diff line number Diff line change 11package org.yapp.apis.book.dto.request
22
3- import jakarta.validation.constraints.NotBlank
43import org.yapp.infra.external.aladin.dto.AladinBookSearchRequest
54
65
76data class BookSearchRequest private constructor(
8- @field:NotBlank(message = "검색어는 필수입니다.")
97 val query : String? = null ,
108 val queryType : String? = null ,
119 val searchTarget : String? = null ,
@@ -16,11 +14,11 @@ data class BookSearchRequest private constructor(
1614 val categoryId : Int? = null
1715) {
1816
17+ fun validQuery (): String = query!!
1918 fun toAladinRequest (): AladinBookSearchRequest {
20- require(! query.isNullOrBlank()) { " 검색어(query)는 필수입니다." }
2119
2220 return AladinBookSearchRequest .create(
23- query = this .query ,
21+ query = this .validQuery() ,
2422 queryType = this .queryType,
2523 searchTarget = this .searchTarget,
2624 maxResults = this .maxResults,
Original file line number Diff line number Diff line change 11package org.yapp.globalutils.util
22
3-
43object RegexUtils {
54
65 val EMAIL_PATTERN = Regex (" ^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\ .[A-Za-z]{2,}$" )
76
87 val PROFILE_IMAGE_URL_PATTERN = Regex (" ^https?://[a-zA-Z0-9.-]+(/.*)?$" )
98
9+ const val NOT_BLANK_AND_NOT_NULL_STRING_PATTERN = " ^(?!null$|NULL$|\\ s*$).+" // Removed the old ISBN pattern
1010
1111 fun isValidEmail (email : String ): Boolean {
1212 return email.matches(EMAIL_PATTERN )
You can’t perform that action at this time.
0 commit comments