Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix word candidates response issue #191

Merged
merged 8 commits into from
Oct 27, 2024
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
Loading