Skip to content

Commit 41eeae2

Browse files
authored
fix: 실시간 지하철 데이터 필드에서 다음역 이름 정보도 포함하여 응답 (#140)
* fix: 실시간 지하철 데이터 필드에서 다음역 이름 정보도 포함하여 응답 * refactor: 리뷰 반영
1 parent d7cbf1a commit 41eeae2

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/main/java/com/example/pace/domain/transit/dto/response/SubwayArrivalResDTO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public static class SubwayArrivalInfoDTO {
3535
private String bstatnNm;
3636
// 상/하행 구분
3737
private String updnLine;
38+
// 다음역 이름
39+
private String nextStationName;
3840
// 몇 정거장 전인지
3941
private Integer beforeSubwayCount;
4042
}

src/main/java/com/example/pace/domain/transit/service/query/SubwayApiQueryService.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.example.pace.domain.transit.dto.response.SubwayArrivalResDTO;
66
import com.example.pace.domain.transit.dto.response.SubwayStationResDTO;
77
import com.example.pace.domain.transit.exception.SubwayApiException;
8+
import com.example.pace.domain.transit.exception.TransitException;
89
import com.example.pace.domain.transit.exception.code.SubwayApiErrorCode;
10+
import com.example.pace.domain.transit.exception.code.TransitErrorCode;
911
import com.example.pace.domain.transit.service.SubwayNetworkService;
1012
import com.example.pace.global.config.SubwayProperties;
1113
import java.util.List;
@@ -32,6 +34,15 @@ public List<SubwayArrivalResDTO.SubwayArrivalInfoDTO> getLiveSubwayStation(
3234
String endStationName = request.getEndStationName();
3335
String lineName = request.getLineName();
3436

37+
List<SubwayStationResDTO> path = subwayNetworkService.getStationsBetween(lineName, startStationName,
38+
endStationName);
39+
40+
if (path == null || path.isEmpty()) {
41+
throw new TransitException(TransitErrorCode.TRANSIT_BUS_NOT_FOUND);
42+
}
43+
44+
String nextStationName = (path.size() > 1) ? path.get(1).getStationName() : "종점";
45+
3546
String url = UriComponentsBuilder.fromUriString(subwayProperties.getApiUrl())
3647
.pathSegment(subwayProperties.getKey(), "json", "realtimeStationArrival",
3748
"0", "10", startStationName)
@@ -57,9 +68,11 @@ public List<SubwayArrivalResDTO.SubwayArrivalInfoDTO> getLiveSubwayStation(
5768

5869
return response.getRealtimeArrivalList().stream()
5970
.filter(arrival -> isSameLine(arrival.getSubwayId(), lineName))
60-
.filter(arrival -> isInboundDirection(arrival, startStationName, endStationName, lineName))
71+
.filter(arrival -> isInboundDirection(arrival, path, lineName))
6172
.filter(arrival -> isReachDestination(arrival, startStationName, endStationName, lineName))
6273
.peek(arrival -> {
74+
arrival.setNextStationName(nextStationName);
75+
6376
int count = subwayNetworkService.getStationCountBetween(
6477
lineName,
6578
arrival.getArvlMsg3(),
@@ -74,13 +87,9 @@ public List<SubwayArrivalResDTO.SubwayArrivalInfoDTO> getLiveSubwayStation(
7487
// 상행인지, 하행인지 판별(상행이라고 했을 때 true면 상행, false면 하행)
7588
private boolean isInboundDirection(
7689
SubwayArrivalResDTO.SubwayArrivalInfoDTO arrival,
77-
String start,
78-
String end,
90+
List<SubwayStationResDTO> path,
7991
String lineName
8092
) {
81-
// 출발지부터 목적지까지의 경로
82-
List<SubwayStationResDTO> path = subwayNetworkService.getStationsBetween(lineName, start, end);
83-
8493
// 출발지 역이 목적지 역인 경우 그냥 모든 열차를 보여줌
8594
// 추후 상의를 통하여 어케할지 정하기
8695
if (path.size() == 1) {

0 commit comments

Comments
 (0)