55import com .example .pace .domain .transit .dto .response .SubwayArrivalResDTO ;
66import com .example .pace .domain .transit .dto .response .SubwayStationResDTO ;
77import com .example .pace .domain .transit .exception .SubwayApiException ;
8+ import com .example .pace .domain .transit .exception .TransitException ;
89import com .example .pace .domain .transit .exception .code .SubwayApiErrorCode ;
10+ import com .example .pace .domain .transit .exception .code .TransitErrorCode ;
911import com .example .pace .domain .transit .service .SubwayNetworkService ;
1012import com .example .pace .global .config .SubwayProperties ;
1113import 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