Skip to content

Commit

Permalink
Merge pull request #191 from dnd-side-project/fix/#181
Browse files Browse the repository at this point in the history
fix word candidates response issue
  • Loading branch information
miraexhoi authored Oct 27, 2024
2 parents 92a7a8b + bc94e38 commit 1cdfa20
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,8 +79,11 @@ public List<ListWordInfoDto> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public List<Word> findAllBy(WordConditionDto wordConditionDto) {
public WordCandidateDto findCandidateAllBy(String target) {
List<String> result = queryFactory.select(word.name)
.from(word)
.where(word.name.endsWith(target))
.where(word.name.contains(target))
.fetch();

return WordRepositoryMapper.to(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,7 +68,7 @@ public ResponseEntity<Long> getTotalWordCount() {
}

@GetMapping("/candidates")
public ResponseEntity<InputWordCandidateResponse> findCandidateAllBy(String name) {
public ResponseEntity<InputWordCandidateResponse> findCandidateAllBy(@RequestParam String name) {
InputWordCandidateDto result = wordService.findCandidateAllBy(name);

return ResponseEntity.ok(WordControllerMapper.to(result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ", ";
Expand Down

0 comments on commit 1cdfa20

Please sign in to comment.