From 724bc8359204ee32a7bf0a5aefe54deb572d42e1 Mon Sep 17 00:00:00 2001 From: imenuuu Date: Sun, 13 Oct 2024 14:44:39 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=98=81=EC=96=B4=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=EC=8B=9C=20=EC=99=80=EC=9D=B8=20=EC=98=81=EB=AC=B8?= =?UTF-8?q?=EB=AA=85=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wineyapi/wine/convertor/WineConvertor.java | 18 +++++++++++++++--- .../wineyapi/wine/service/WineServiceImpl.java | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java b/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java index d2ce36cf..b3d67241 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java +++ b/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java @@ -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; @@ -75,18 +76,29 @@ public List toRecommendWineDto(List w return recommendWineDTOS; } - public PageResponse> SearchWineList(Page wines) { + public PageResponse> SearchWineList(Page wines, String content) { List 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()) diff --git a/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java b/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java index 5b8beaa0..4673718d 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java +++ b/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java @@ -80,7 +80,7 @@ public PageResponse> searchWineList(Integer pag }else{ wines = wineRepository.findByNameContainingOrEngNameContaining(content,content,pageable); } - return wineConvertor.SearchWineList(wines); + return wineConvertor.SearchWineList(wines, content); } @Override