Skip to content

Commit

Permalink
[fix] 빈 파람값 validation 추가 #66
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdtkdgns committed Jul 27, 2023
1 parent 42c73df commit 72fc244
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@ public class GetRelativeSearchListUseCase {

@Transactional
public SearchListResponse execute(String word) {
validateExecution(word);
ZSetOperations<String, String> zSetOperations = redisTemplate.opsForZSet();
List<String> autoCompleteList = new ArrayList<>();
Long rank = zSetOperations.rank(SEARCH_KEY, word);
Expand All @@ -30,6 +32,10 @@ public SearchListResponse execute(String word) {
return SearchListResponse.from(autoCompleteList);
}

private void validateExecution(String word) {
StringParamUtil.checkEmptyString(word);
}

private List<String> getAutoCompleteList(Set<String> rangeList, String keyword) {
return rangeList.stream()
.filter(value -> value.endsWith(ASTERISK) && value.startsWith(keyword))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class SearchArchivingUseCase {

@Transactional
public SearchResponse execute(Pageable pageable, ArchivingType type, String word) {
validateExecution(word);
Long userId = SecurityUtil.getCurrentUserId();
Set<Long> tagArchivingIds = getTagArchivingIds(userId, word);
SliceResponse<ArchivingResponse> my;
Expand All @@ -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<Long> getTagArchivingIds(Long userId, String word) {
List<Tag> tags = tagAdaptor.findAllByUserIdAndName(userId, word);
return contentTagGroupAdaptor.queryContentTagGroupByTagInWithContent(tags).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 입니다."),

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 72fc244

Please sign in to comment.