Skip to content

Commit

Permalink
#33 [Update] 업장 검색 예외처리 추가
Browse files Browse the repository at this point in the history
모든 값이 null로 들어올 때 예외처리
검색어가 1글자일 때 예외처리
  • Loading branch information
Anna-Jin committed Jul 31, 2022
1 parent 32975c7 commit a3100a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/mpnp/baechelin/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +29,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/store")
@Validated
public class StoreController {

private final StoreService storeService;
Expand Down Expand Up @@ -103,12 +107,16 @@ public Map<String, List<String>> 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<String> 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);
}
}

0 comments on commit a3100a0

Please sign in to comment.