diff --git a/Api/src/main/java/allchive/server/api/common/util/StringParamUtil.java b/Api/src/main/java/allchive/server/api/common/util/StringParamUtil.java new file mode 100644 index 00000000..0cc94558 --- /dev/null +++ b/Api/src/main/java/allchive/server/api/common/util/StringParamUtil.java @@ -0,0 +1,13 @@ +package allchive.server.api.common.util; + +import allchive.server.core.error.exception.EmptyParamValueException; +import org.springframework.stereotype.Component; + +@Component +public class StringParamUtil { + public static void checkEmptyString(String param) { + if (param.equals("")) { + throw EmptyParamValueException.EXCEPTION; + } + } +} diff --git a/Api/src/main/java/allchive/server/api/search/service/GetRelativeSearchListUseCase.java b/Api/src/main/java/allchive/server/api/search/service/GetRelativeSearchListUseCase.java index d1d3f681..f148d8b5 100644 --- a/Api/src/main/java/allchive/server/api/search/service/GetRelativeSearchListUseCase.java +++ b/Api/src/main/java/allchive/server/api/search/service/GetRelativeSearchListUseCase.java @@ -3,6 +3,7 @@ import static allchive.server.core.consts.AllchiveConst.SEARCH_KEY; import static jodd.util.StringPool.ASTERISK; +import allchive.server.api.common.util.StringParamUtil; import allchive.server.api.search.model.dto.response.SearchListResponse; import allchive.server.core.annotation.UseCase; import java.util.ArrayList; @@ -20,6 +21,7 @@ public class GetRelativeSearchListUseCase { @Transactional public SearchListResponse execute(String word) { + validateExecution(word); ZSetOperations zSetOperations = redisTemplate.opsForZSet(); List autoCompleteList = new ArrayList<>(); Long rank = zSetOperations.rank(SEARCH_KEY, word); @@ -30,6 +32,10 @@ public SearchListResponse execute(String word) { return SearchListResponse.from(autoCompleteList); } + private void validateExecution(String word) { + StringParamUtil.checkEmptyString(word); + } + private List getAutoCompleteList(Set rangeList, String keyword) { return rangeList.stream() .filter(value -> value.endsWith(ASTERISK) && value.startsWith(keyword)) diff --git a/Api/src/main/java/allchive/server/api/search/service/SearchArchivingUseCase.java b/Api/src/main/java/allchive/server/api/search/service/SearchArchivingUseCase.java index bb0c88b6..dfb0a313 100644 --- a/Api/src/main/java/allchive/server/api/search/service/SearchArchivingUseCase.java +++ b/Api/src/main/java/allchive/server/api/search/service/SearchArchivingUseCase.java @@ -3,6 +3,7 @@ import allchive.server.api.archiving.model.dto.response.ArchivingResponse; import allchive.server.api.common.slice.SliceResponse; +import allchive.server.api.common.util.StringParamUtil; import allchive.server.api.config.security.SecurityUtil; import allchive.server.api.search.model.dto.response.SearchResponse; import allchive.server.api.search.model.enums.ArchivingType; @@ -39,6 +40,7 @@ public class SearchArchivingUseCase { @Transactional public SearchResponse execute(Pageable pageable, ArchivingType type, String word) { + validateExecution(word); Long userId = SecurityUtil.getCurrentUserId(); Set tagArchivingIds = getTagArchivingIds(userId, word); SliceResponse my; @@ -62,6 +64,10 @@ public SearchResponse execute(Pageable pageable, ArchivingType type, String word return null; } + private void validateExecution(String word) { + StringParamUtil.checkEmptyString(word); + } + private Set getTagArchivingIds(Long userId, String word) { List tags = tagAdaptor.findAllByUserIdAndName(userId, word); return contentTagGroupAdaptor.queryContentTagGroupByTagInWithContent(tags).stream() diff --git a/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java b/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java index f73bb7a8..aeb58a0c 100644 --- a/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java +++ b/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java @@ -14,6 +14,7 @@ public enum GlobalErrorCode implements BaseErrorCode { /** Server 오류 * */ HTTP_MESSAGE_NOT_READABLE(BAD_REQUEST, "GLOBAL_400_1", "잘못된 형식의 값을 입력했습니다."), + EMPTY_PARAM_VALUE(BAD_REQUEST, "GLOBAL_400_2", "빈 파람 값을 입력했습니다."), _INTERNAL_SERVER_ERROR(INTERNAL_SERVER, "GLOBAL_500_1", "서버 오류. 관리자에게 문의 부탁드립니다."), INVALID_OAUTH_PROVIDER(INTERNAL_SERVER, "GLOBAL_500_2", "지원하지 않는 OAuth Provider 입니다."), diff --git a/Core/src/main/java/allchive/server/core/error/exception/EmptyParamValueException.java b/Core/src/main/java/allchive/server/core/error/exception/EmptyParamValueException.java new file mode 100644 index 00000000..1f2d37e7 --- /dev/null +++ b/Core/src/main/java/allchive/server/core/error/exception/EmptyParamValueException.java @@ -0,0 +1,14 @@ +package allchive.server.core.error.exception; + + +import allchive.server.core.error.BaseErrorException; +import allchive.server.core.error.GlobalErrorCode; + +public class EmptyParamValueException extends BaseErrorException { + + public static final BaseErrorException EXCEPTION = new EmptyParamValueException(); + + private EmptyParamValueException() { + super(GlobalErrorCode.EMPTY_PARAM_VALUE); + } +}