Skip to content

Commit

Permalink
refactor : 영어 검색시 와인 영문명 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
imenuuu committed Oct 13, 2024
1 parent fcb35c4 commit 724bc83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -75,18 +76,29 @@ public List<RecommendWineDTO> toRecommendWineDto(List<WineRepository.WineList> w
return recommendWineDTOS;
}

public PageResponse<List<WineResponse.SearchWineDto>> SearchWineList(Page<Wine> wines) {
public PageResponse<List<WineResponse.SearchWineDto>> SearchWineList(Page<Wine> wines, String content) {
List<WineResponse.SearchWineDto> wineDtoList = new ArrayList<>();

wines.getContent().forEach(
result -> wineDtoList.add(
convertWineInfo(result)
convertWineInfo(result, content)
)
);
return new PageResponse<>(wines.isLast(), wines.getTotalElements(), wineDtoList);
}

private WineResponse.SearchWineDto convertWineInfo(Wine result) {
private WineResponse.SearchWineDto convertWineInfo(Wine result, String content) {
String name ="";
if(content !=null){
if (Pattern.matches("^[a-zA-Z]*$", content)
) {
name = result.getEngName();
} else {
name = result.getName();
}
}else{
name = result.getName();
}
return WineResponse.SearchWineDto
.builder()
.wineId(result.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public PageResponse<List<WineResponse.SearchWineDto>> searchWineList(Integer pag
}else{
wines = wineRepository.findByNameContainingOrEngNameContaining(content,content,pageable);
}
return wineConvertor.SearchWineList(wines);
return wineConvertor.SearchWineList(wines, content);
}

@Override
Expand Down

0 comments on commit 724bc83

Please sign in to comment.