From bf48d8bfa424fe7bdc1e5e613a4e7f4bc1571ca0 Mon Sep 17 00:00:00 2001 From: hellozo0 Date: Wed, 17 Jan 2024 18:39:21 +0900 Subject: [PATCH] =?UTF-8?q?#149=20[feat]=20@Valid=20=EB=B6=99=EC=9D=B4?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moddy/server/controller/model/ModelController.java | 3 ++- .../model/dto/request/ModelApplicationRequest.java | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/moddy/server/controller/model/ModelController.java b/src/main/java/com/moddy/server/controller/model/ModelController.java index 66115002..f7d0e07c 100644 --- a/src/main/java/com/moddy/server/controller/model/ModelController.java +++ b/src/main/java/com/moddy/server/controller/model/ModelController.java @@ -18,6 +18,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -103,7 +104,7 @@ public SuccessNonDataResponse submitModelApplication( @Parameter(hidden = true) @UserId Long userId, @RequestPart(value = "modelImgUrl", required = false) MultipartFile modelImgUrl, @RequestPart(value = "applicationCaptureImgUrl", required = false) MultipartFile applicationCaptureImgUrl, - @RequestPart(value = "applicationInfo") ModelApplicationRequest applicationInfo) { + @RequestPart(value = "applicationInfo") @Valid ModelApplicationRequest applicationInfo) { modelService.postApplication(userId, modelImgUrl, applicationCaptureImgUrl, applicationInfo); return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS); } diff --git a/src/main/java/com/moddy/server/controller/model/dto/request/ModelApplicationRequest.java b/src/main/java/com/moddy/server/controller/model/dto/request/ModelApplicationRequest.java index 8d765e1b..fb79b66c 100644 --- a/src/main/java/com/moddy/server/controller/model/dto/request/ModelApplicationRequest.java +++ b/src/main/java/com/moddy/server/controller/model/dto/request/ModelApplicationRequest.java @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; @@ -15,16 +16,17 @@ public record ModelApplicationRequest( @Schema(description = "모델의 현재 머리 기장 예시입니다.", example ="SHORT") @Enumerated(EnumType.STRING) HairLength hairLength, - @Schema(description = "PreferHaireStyle의 예시 JSON 배열 포맷입니다.", example ="[\"NORMAL_CUT\", \"ALL_COLOR\"]") + @Schema(description = "PreferHaireStyle의 예시입니다.", example ="[\"NORMAL_CUT\", \"ALL_COLOR\"]") @ValidPreferHairStyles List preferHairStyles, @Schema(description = "모델이 원하는 헤어스타일 예시입니다.", example = "안녕하세요 저는 숱을 많이 친 허쉬컷이 하고 싶어요 근데 머리가 곱슬이라 매직도 같이 해야지 이쁘게 될것 같아요. 그리고 머리가 얇아서 그거 감안하고 해야할것 같습니다.") @Size(min = 0, max = 200, message = "hairDetail은 0~200 글자수 사이의 글자입니다.") + @NotBlank String hairDetail, - @Schema(description = "HairServiceRecords 의 예시 JSON 배열 포맷입니다.", example = "[{\"hairService\": \"PERM\", \"hairServiceTerm\": \"UNDER_ONE\"}, {\"hairService\": \"BLACK\", \"hairServiceTerm\": \"ABOVE_TWELVE\"}]") + @Size(min = 0, max = 3, message = "hairServiceRecord는 선택사항이며, 3개까지 추가 가능합니다.") List hairServiceRecords, @Schema(description = "모델의 인스타그램 예시입니다.", example ="hizo0") - @Pattern(regexp = "[^@]+[_.]+[^@]+", message = "인스타 그램 아이디에는 @는 들어올 수 없지만 _와 .는 가능합니다.") + @Pattern(regexp = "^[^@\\s]+[_\\.]+[^\\s]+$", message = "인스타 그램 아이디에는 @는 들어올 수 없지만 _와 .는 가능합니다.") String instagramId ) { public List getHairServiceRecords() {