diff --git a/src/main/java/com/dnd/spaced/domain/word/application/WordService.java b/src/main/java/com/dnd/spaced/domain/word/application/WordService.java index 26262a9..93a4864 100644 --- a/src/main/java/com/dnd/spaced/domain/word/application/WordService.java +++ b/src/main/java/com/dnd/spaced/domain/word/application/WordService.java @@ -12,6 +12,7 @@ import com.dnd.spaced.domain.word.application.dto.response.WordSearchInfoDto; import com.dnd.spaced.domain.word.application.event.dto.request.FoundWordPopularViewCountEvent; import com.dnd.spaced.domain.word.application.event.dto.request.FoundWordViewCountEvent; +import com.dnd.spaced.domain.word.application.exception.CandidatesNotFoundException; import com.dnd.spaced.domain.word.application.exception.WordNotFoundException; import com.dnd.spaced.domain.word.domain.Word; import com.dnd.spaced.domain.word.domain.repository.PopularWordRepository; @@ -78,8 +79,11 @@ public List findRandomWords() { } public InputWordCandidateDto findCandidateAllBy(String target) { - WordCandidateDto result = wordRepository.findCandidateAllBy(target); + if (target == null || target.trim().isEmpty()) { + throw new CandidatesNotFoundException(); + } + WordCandidateDto result = wordRepository.findCandidateAllBy(target); return WordServiceMapper.from(result); } diff --git a/src/main/java/com/dnd/spaced/domain/word/application/exception/CandidatesNotFoundException.java b/src/main/java/com/dnd/spaced/domain/word/application/exception/CandidatesNotFoundException.java new file mode 100644 index 0000000..6431478 --- /dev/null +++ b/src/main/java/com/dnd/spaced/domain/word/application/exception/CandidatesNotFoundException.java @@ -0,0 +1,11 @@ +package com.dnd.spaced.domain.word.application.exception; + +import com.dnd.spaced.global.exception.BaseClientException; +import com.dnd.spaced.global.exception.ExceptionCode; + +public class CandidatesNotFoundException extends BaseClientException { + + public CandidatesNotFoundException() { + super(ExceptionCode.CANDIDATE_NOT_FOUND); + } +} diff --git a/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java b/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java index a1d61a6..1d74eb0 100644 --- a/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java +++ b/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java @@ -112,7 +112,7 @@ public List findAllBy(WordConditionDto wordConditionDto) { public WordCandidateDto findCandidateAllBy(String target) { List result = queryFactory.select(word.name) .from(word) - .where(word.name.endsWith(target)) + .where(word.name.contains(target)) .fetch(); return WordRepositoryMapper.to(result); diff --git a/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java b/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java index eefc9f7..1ff0b5f 100644 --- a/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java +++ b/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -67,7 +68,7 @@ public ResponseEntity getTotalWordCount() { } @GetMapping("/candidates") - public ResponseEntity findCandidateAllBy(String name) { + public ResponseEntity findCandidateAllBy(@RequestParam String name) { InputWordCandidateDto result = wordService.findCandidateAllBy(name); return ResponseEntity.ok(WordControllerMapper.to(result)); diff --git a/src/main/java/com/dnd/spaced/global/exception/ExceptionCode.java b/src/main/java/com/dnd/spaced/global/exception/ExceptionCode.java index 12784ad..399a087 100644 --- a/src/main/java/com/dnd/spaced/global/exception/ExceptionCode.java +++ b/src/main/java/com/dnd/spaced/global/exception/ExceptionCode.java @@ -41,5 +41,6 @@ public enum ExceptionCode { QUIZ_NOT_FOUND, NOT_ENOUGH_QUESTIONS_FOR_CATEGORY, ACCOUNT_UNAUTHORIZED, - REPORT_NOT_FOUND + REPORT_NOT_FOUND, + CANDIDATE_NOT_FOUND } diff --git a/src/main/java/com/dnd/spaced/global/exception/ExceptionTranslator.java b/src/main/java/com/dnd/spaced/global/exception/ExceptionTranslator.java index 3f87510..e075028 100644 --- a/src/main/java/com/dnd/spaced/global/exception/ExceptionTranslator.java +++ b/src/main/java/com/dnd/spaced/global/exception/ExceptionTranslator.java @@ -202,6 +202,11 @@ public enum ExceptionTranslator { HttpStatus.NOT_FOUND, ExceptionCode.REPORT_NOT_FOUND, "해당 신고를 찾을 수 없습니다." + ), + CANDIDATE_NOT_FOUND_EXCEPTION( + HttpStatus.NOT_FOUND, + ExceptionCode.CANDIDATE_NOT_FOUND, + "일치하는 용어 이름 검색어 후보군이 없습니다." ); private static final String PARAMETER_SEPARATOR = ", ";