From f9ad4de732f4f5a4731796b88af8b3f37a672364 Mon Sep 17 00:00:00 2001 From: Photogrammer <81505228+JuneParkCode@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:40:50 +0900 Subject: [PATCH] [FIX] YN Enum Error / RouteStation Controller Error / Like Query Error (#69) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 수정 전 기능 - ENUM YN 에 대해서 "0", "1" 처리 - BusRouteStationController @Service 어노테이션으로 되어있는 문제 - `Like` 쿼리 ## 수정 후 기능 - "Y" "N" 처리 - @RestController 적용 - `StartWIth` 쿼리 ## 수정 의도 - 버그 수정 Closes #68 --- .../server/bus/controller/BusRouteStationController.java | 4 ++-- .../java/com/talkka/server/bus/dao/BusRouteRepository.java | 2 +- .../java/com/talkka/server/bus/dao/BusStationRepository.java | 2 +- .../main/java/com/talkka/server/bus/enums/CenterStation.java | 4 ++-- .../main/java/com/talkka/server/bus/enums/TurnStation.java | 2 +- .../java/com/talkka/server/bus/service/BusRouteService.java | 2 +- .../com/talkka/server/bus/service/BusStationService.java | 2 +- .../talkka/server/subway/dao/SubwayStationRepository.java | 2 +- .../talkka/server/subway/service/SubwayStationService.java | 2 +- .../com/talkka/server/bus/service/BusRouteServiceTest.java | 4 ++-- .../com/talkka/server/bus/service/BusStationServiceTest.java | 5 +++-- .../server/subway/service/SubwayStationServiceTest.java | 2 +- 12 files changed, 17 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/com/talkka/server/bus/controller/BusRouteStationController.java b/server/src/main/java/com/talkka/server/bus/controller/BusRouteStationController.java index 0b868ee1..c3d7f50b 100644 --- a/server/src/main/java/com/talkka/server/bus/controller/BusRouteStationController.java +++ b/server/src/main/java/com/talkka/server/bus/controller/BusRouteStationController.java @@ -3,11 +3,11 @@ import java.util.List; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; 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; import com.talkka.server.bus.dto.BusRouteStationRespDto; import com.talkka.server.bus.service.BusRouteStationService; @@ -16,7 +16,7 @@ import lombok.RequiredArgsConstructor; -@Service +@RestController @RequiredArgsConstructor @RequestMapping("/api/bus/route-station") public class BusRouteStationController { diff --git a/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java b/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java index a9adc185..53270bca 100644 --- a/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java +++ b/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java @@ -13,6 +13,6 @@ public interface BusRouteRepository extends JpaRepository Optional findByApiRouteId(String apiRouteId); - List findAllByRouteNameLikeOrderByRouteNameAsc(String routeName); + List findAllByRouteNameStartingWithOrderByRouteNameAsc(String routeName); } diff --git a/server/src/main/java/com/talkka/server/bus/dao/BusStationRepository.java b/server/src/main/java/com/talkka/server/bus/dao/BusStationRepository.java index c0da3389..3eb8c389 100644 --- a/server/src/main/java/com/talkka/server/bus/dao/BusStationRepository.java +++ b/server/src/main/java/com/talkka/server/bus/dao/BusStationRepository.java @@ -10,7 +10,7 @@ public interface BusStationRepository extends JpaRepository { Optional findByApiStationId(String apiStationId); - List findByStationNameLikeOrderByStationNameAsc(String stationName); + List findByStationNameStartingWithOrderByStationNameAsc(String stationName); boolean existsByApiStationId(String apiStationId); } diff --git a/server/src/main/java/com/talkka/server/bus/enums/CenterStation.java b/server/src/main/java/com/talkka/server/bus/enums/CenterStation.java index b588bc64..7fbdbc48 100644 --- a/server/src/main/java/com/talkka/server/bus/enums/CenterStation.java +++ b/server/src/main/java/com/talkka/server/bus/enums/CenterStation.java @@ -6,8 +6,8 @@ @Getter public enum CenterStation implements EnumCodeInterface { - NOT_CENTER_STATION("0"), - CENTER_STATION("1"); + NOT_CENTER_STATION("N"), + CENTER_STATION("Y"); private final String code; diff --git a/server/src/main/java/com/talkka/server/bus/enums/TurnStation.java b/server/src/main/java/com/talkka/server/bus/enums/TurnStation.java index ee94a332..356947a9 100644 --- a/server/src/main/java/com/talkka/server/bus/enums/TurnStation.java +++ b/server/src/main/java/com/talkka/server/bus/enums/TurnStation.java @@ -6,7 +6,7 @@ @Getter public enum TurnStation implements EnumCodeInterface { - TURN_STATION("1"), NOT_TURN_STATION("0"); + TURN_STATION("Y"), NOT_TURN_STATION("N"); private final String code; diff --git a/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java b/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java index e2b05100..1b9b8e30 100644 --- a/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java +++ b/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java @@ -30,7 +30,7 @@ public List getRoutes() { } public List getRoutesByRouteName(String routeName) { - return busRouteRepository.findAllByRouteNameLikeOrderByRouteNameAsc(routeName).stream() + return busRouteRepository.findAllByRouteNameStartingWithOrderByRouteNameAsc(routeName).stream() .map(BusRouteRespDto::of) .toList(); } diff --git a/server/src/main/java/com/talkka/server/bus/service/BusStationService.java b/server/src/main/java/com/talkka/server/bus/service/BusStationService.java index 3a2938b4..c5080df4 100644 --- a/server/src/main/java/com/talkka/server/bus/service/BusStationService.java +++ b/server/src/main/java/com/talkka/server/bus/service/BusStationService.java @@ -24,7 +24,7 @@ public BusStationRespDto getStationById(Long stationId) { } public List getStationsByStationName(String stationName) { - return busStationRepository.findByStationNameLikeOrderByStationNameAsc(stationName).stream() + return busStationRepository.findByStationNameStartingWithOrderByStationNameAsc(stationName).stream() .map(BusStationRespDto::of) .toList(); } diff --git a/server/src/main/java/com/talkka/server/subway/dao/SubwayStationRepository.java b/server/src/main/java/com/talkka/server/subway/dao/SubwayStationRepository.java index 692cc05e..a90d8108 100644 --- a/server/src/main/java/com/talkka/server/subway/dao/SubwayStationRepository.java +++ b/server/src/main/java/com/talkka/server/subway/dao/SubwayStationRepository.java @@ -7,7 +7,7 @@ @Repository public interface SubwayStationRepository extends JpaRepository { - List findByStationNameLikeOrderByStationNameAsc(String stationName); + List findByStationNameStartingWithOrderByStationNameAsc(String stationName); boolean existsByStationCode(String stationCode); } diff --git a/server/src/main/java/com/talkka/server/subway/service/SubwayStationService.java b/server/src/main/java/com/talkka/server/subway/service/SubwayStationService.java index 44251269..ac849db0 100644 --- a/server/src/main/java/com/talkka/server/subway/service/SubwayStationService.java +++ b/server/src/main/java/com/talkka/server/subway/service/SubwayStationService.java @@ -26,7 +26,7 @@ public SubwayStationRespDto findByStationId(Long stationId) { } public List findByStationName(String stationName) { - return stationRepository.findByStationNameLikeOrderByStationNameAsc(stationName).stream() + return stationRepository.findByStationNameStartingWithOrderByStationNameAsc(stationName).stream() .map(SubwayStationRespDto::of) .toList(); } diff --git a/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java index 7da099cc..50b5e6f6 100644 --- a/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java +++ b/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java @@ -103,14 +103,14 @@ public class GetRoutesByRouteNameTest { String routeName = "7800"; var entityList = List.of(getBusRouteEntity(1L), getBusRouteEntity(2L)); var expectedList = List.of(getBusRouteRespDto(1L), getBusRouteRespDto(2L)); - given(busRouteRepository.findAllByRouteNameLikeOrderByRouteNameAsc(any(String.class))).willReturn( + given(busRouteRepository.findAllByRouteNameStartingWithOrderByRouteNameAsc(any(String.class))).willReturn( entityList); // when var resultList = busRouteService.getRoutesByRouteName(routeName); // then - verify(busRouteRepository, times(1)).findAllByRouteNameLikeOrderByRouteNameAsc(anyString()); + verify(busRouteRepository, times(1)).findAllByRouteNameStartingWithOrderByRouteNameAsc(anyString()); assertThat(resultList).containsAll(expectedList); } diff --git a/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java index b6191cfb..5731fac7 100644 --- a/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java +++ b/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java @@ -104,12 +104,13 @@ public class GetStationsByStationNameTest { getBusStationEntity(1L), getBusStationEntity(12L) ); - given(busStationRepository.findByStationNameLikeOrderByStationNameAsc(anyString())).willReturn(entityList); + given(busStationRepository.findByStationNameStartingWithOrderByStationNameAsc(anyString())).willReturn( + entityList); // when var result = busStationService.getStationsByStationName(stationName); // then assertThat(result).containsAll(expected); - verify(busStationRepository, times(1)).findByStationNameLikeOrderByStationNameAsc(anyString()); + verify(busStationRepository, times(1)).findByStationNameStartingWithOrderByStationNameAsc(anyString()); } } diff --git a/server/src/test/java/com/talkka/server/subway/service/SubwayStationServiceTest.java b/server/src/test/java/com/talkka/server/subway/service/SubwayStationServiceTest.java index 50654649..d44d839a 100644 --- a/server/src/test/java/com/talkka/server/subway/service/SubwayStationServiceTest.java +++ b/server/src/test/java/com/talkka/server/subway/service/SubwayStationServiceTest.java @@ -110,7 +110,7 @@ public class findByStationName { SubwayStationRespDto.of(subwayStationEntities.get(1)) ); - given(stationRepository.findByStationNameLikeOrderByStationNameAsc(anyString())).willReturn( + given(stationRepository.findByStationNameStartingWithOrderByStationNameAsc(anyString())).willReturn( subwayStationEntities); //when