[241114 TIL] AI 검증 비즈니스 프로젝트

    카테고리, 가게, 리뷰 CRUD API 구현

    • 코드리뷰 수정사항 반영
    • Soft Delete 수정
    • 리뷰 CRUD 추가 기능 구현

    코드리뷰 수정사항 반영

     

    ✔️ 카테고리 아이디 null 체크 부분 ➡️ 공백값도 같이 체크 가능하게 변경

     

    • 수정 전
    if (categoryId == null) 

     

    • 수정 후
    if (!StringUtils.hasText(String.valueOf(categoryId)))

     

    StringUtils.hasText 이용

     

    내부 로직

    public static boolean hasText(@Nullable String str) {
        return str != null && !str.isEmpty() && containsText(str);
    }
    
    private static boolean containsText(CharSequence str) {
        int strLen = str.length();
        
        for(int i = 0; i < strLen; ++i) {
          if (!Character.isWhitespace(str.charAt(i))) {
            return true;
          }
        }
        
        return false;
    }

     

    • str 이 null 인가
    • str이 빈 문자열 ("")인가
    • str이 공백으로만(whitespace) 이루어져 있는가 

    + Recent posts