From a3100a05f98cc9f90770c8eb5caccd4ea0fd0d50 Mon Sep 17 00:00:00 2001 From: Anna-Jin Date: Mon, 1 Aug 2022 04:33:23 +0900 Subject: [PATCH] =?UTF-8?q?#33=20[Update]=20=EC=97=85=EC=9E=A5=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 모든 값이 null로 들어올 때 예외처리 검색어가 1글자일 때 예외처리 --- .../java/com/mpnp/baechelin/exception/ErrorCode.java | 1 + .../baechelin/store/controller/StoreController.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java b/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java index bd64ecc..cccdc8f 100644 --- a/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java +++ b/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java @@ -22,6 +22,7 @@ public enum ErrorCode { API_LOAD_FAILURE(500, "E-ALF500", "API 로딩에 실패하였습니다."), API_NO_RESULT(500, "E-ANR500", "API 결과가 존재하지 않습니다."), NULL_POINTER_EXCEPTION(500, "E-NPE500", "빈 값이 들어올 수 없습니다."), + KEYWORD_ARE_NEEDED(500, "E-KAE500", "검색어를 입력해주세요."), IMAGE_PROCESS_FAIL(500,"E-IPF500","이미지 오류 발생"); private final int status; diff --git a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java index 5c9bfbd..3ecdf65 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -4,20 +4,23 @@ import com.mpnp.baechelin.exception.ErrorCode; import com.mpnp.baechelin.login.jwt.AuthToken; import com.mpnp.baechelin.login.jwt.AuthTokenProvider; -import com.mpnp.baechelin.store.dto.StoreCardResponseDto; import com.mpnp.baechelin.store.dto.StoreDetailResponseDto; import com.mpnp.baechelin.store.dto.StorePagedResponseDto; import com.mpnp.baechelin.store.service.StoreService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.userdetails.User; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; +import javax.validation.constraints.Size; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -26,6 +29,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/store") +@Validated public class StoreController { private final StoreService storeService; @@ -103,12 +107,16 @@ public Map> getSigungu(@RequestParam String sido) { public StorePagedResponseDto searchStoresByKeyword( @RequestParam(required = false) String sido, @RequestParam(required = false) String sigungu, - @RequestParam(required = false) String keyword, + @RequestParam(required = false) @Size(min = 2, message = "검색어는 두글자 이상 입력해주세요.") String keyword, @RequestParam(required = false) String category, @RequestParam(required = false) List facility, @PageableDefault Pageable pageable, @AuthenticationPrincipal User user) { + if (StringUtils.isEmpty(sido) && StringUtils.isEmpty(sigungu) && StringUtils.isEmpty(keyword) && StringUtils.isEmpty(category) && ObjectUtils.isEmpty(facility)) { + throw new CustomException(ErrorCode.KEYWORD_ARE_NEEDED); + } + return storeService.searchStores(sido, sigungu, keyword, category, facility, user == null ? null : user.getUsername(), pageable); } } \ No newline at end of file