Skip to content

Commit

Permalink
[FIX] YN Enum Error / RouteStation Controller Error / Like Query Error (
Browse files Browse the repository at this point in the history
#69)

## 수정 전 기능
- ENUM YN 에 대해서 "0", "1" 처리
- BusRouteStationController @service 어노테이션으로 되어있는 문제
- `Like` 쿼리

## 수정 후 기능
- "Y" "N" 처리
- @RestController 적용
- `StartWIth` 쿼리

## 수정 의도
- 버그 수정

Closes #68
  • Loading branch information
JuneParkCode authored Aug 13, 2024
1 parent e19ecb8 commit f9ad4de
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +16,7 @@

import lombok.RequiredArgsConstructor;

@Service
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/bus/route-station")
public class BusRouteStationController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public interface BusRouteRepository extends JpaRepository<BusRouteEntity, Long>

Optional<BusRouteEntity> findByApiRouteId(String apiRouteId);

List<BusRouteEntity> findAllByRouteNameLikeOrderByRouteNameAsc(String routeName);
List<BusRouteEntity> findAllByRouteNameStartingWithOrderByRouteNameAsc(String routeName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface BusStationRepository extends JpaRepository<BusStationEntity, Long> {
Optional<BusStationEntity> findByApiStationId(String apiStationId);

List<BusStationEntity> findByStationNameLikeOrderByStationNameAsc(String stationName);
List<BusStationEntity> findByStationNameStartingWithOrderByStationNameAsc(String stationName);

boolean existsByApiStationId(String apiStationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<BusRouteRespDto> getRoutes() {
}

public List<BusRouteRespDto> getRoutesByRouteName(String routeName) {
return busRouteRepository.findAllByRouteNameLikeOrderByRouteNameAsc(routeName).stream()
return busRouteRepository.findAllByRouteNameStartingWithOrderByRouteNameAsc(routeName).stream()
.map(BusRouteRespDto::of)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public BusStationRespDto getStationById(Long stationId) {
}

public List<BusStationRespDto> getStationsByStationName(String stationName) {
return busStationRepository.findByStationNameLikeOrderByStationNameAsc(stationName).stream()
return busStationRepository.findByStationNameStartingWithOrderByStationNameAsc(stationName).stream()
.map(BusStationRespDto::of)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Repository
public interface SubwayStationRepository extends JpaRepository<SubwayStationEntity, Long> {
List<SubwayStationEntity> findByStationNameLikeOrderByStationNameAsc(String stationName);
List<SubwayStationEntity> findByStationNameStartingWithOrderByStationNameAsc(String stationName);

boolean existsByStationCode(String stationCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SubwayStationRespDto findByStationId(Long stationId) {
}

public List<SubwayStationRespDto> findByStationName(String stationName) {
return stationRepository.findByStationNameLikeOrderByStationNameAsc(stationName).stream()
return stationRepository.findByStationNameStartingWithOrderByStationNameAsc(stationName).stream()
.map(SubwayStationRespDto::of)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class findByStationName {
SubwayStationRespDto.of(subwayStationEntities.get(1))
);

given(stationRepository.findByStationNameLikeOrderByStationNameAsc(anyString())).willReturn(
given(stationRepository.findByStationNameStartingWithOrderByStationNameAsc(anyString())).willReturn(
subwayStationEntities);

//when
Expand Down

0 comments on commit f9ad4de

Please sign in to comment.