33import com .example .busnotice .domain .bus .res .BusArrInfosDto ;
44import com .example .busnotice .domain .bus .res .BusArrInfosDto .Item ;
55import com .example .busnotice .domain .bus .res .BusInfosDto ;
6+ import com .example .busnotice .domain .bus .res .BusNameAndTypeResponse ;
67import com .example .busnotice .domain .bus .res .SeoulBusArrInfosDto ;
78import com .example .busnotice .domain .bus .res .SeoulBusInfosDto ;
89import com .example .busnotice .domain .bus .res .SeoulBusInfosDto .BusRoute ;
@@ -122,8 +123,8 @@ public class BusService {
122123 return sortedItems .stream ().limit (2 ).collect (Collectors .toList ());
123124 }
124125
125- @ Cacheable (value = "busNames_through_stn" , key = "#p0 + '_' + #p1" )
126- public List <String > 특정_노드_ID를_경유하는_모든_버스들_이름_조회 (String cityName , String nodeId )
126+ // @Cacheable(value = "busNames_through_stn", key = "#p0 + '_' + #p1")
127+ public List <BusNameAndTypeResponse > 특정_노드_ID를_경유하는_모든_버스들_이름_조회 (String cityName , String nodeId )
127128 throws UnsupportedEncodingException {
128129 log .info ("{}_{} 를 경유하는 모든 버스들 이름 캐싱 실패, 메서드 실행" , cityName , nodeId );
129130 String cityCode = busStopService .도시코드_DB_조회 (cityName );
@@ -146,10 +147,26 @@ public class BusService {
146147 throw new BusStopException (StatusCode .NOT_FOUND ,
147148 "해당 버스정류장을 경유하는 버스 노선이 존재하지 않습니다. 버스정류장 노드 ID 를 다시 확인해주세요." );
148149 }
149- List <String > busNames = result .getMsgBody ().getItemList ().stream ()
150- .map (i -> i .getBusRouteNm ()).toList ();
151- System .out .println ("bus names: " + busNames );
152- return busNames ;
150+ List <BusNameAndTypeResponse > list = result .getMsgBody ().getItemList ().stream ()
151+ .map (i -> {
152+ String routeType = "" ;
153+ switch (i .getBusRouteType ()) {
154+ case 1 : routeType = "공항" ; break ;
155+ case 2 : routeType = "마을" ; break ;
156+ case 3 : routeType = "간선" ; break ;
157+ case 4 : routeType = "지선" ; break ;
158+ case 5 : routeType = "순환" ; break ;
159+ case 6 : routeType = "광역" ; break ;
160+ case 7 : routeType = "인천" ; break ;
161+ case 8 : routeType = "경기" ; break ;
162+ case 9 : routeType = "폐지" ; break ;
163+ case 0 : routeType = "공용" ; break ;
164+ default : routeType = "알수없음" ; // 예외 처리
165+ }
166+ return new BusNameAndTypeResponse (i .getBusRouteNm (), routeType );
167+ }
168+ ).toList ();
169+ return list ;
153170 }
154171
155172 String url = "http://apis.data.go.kr/1613000/BusSttnInfoInqireService/getSttnThrghRouteList" ;
@@ -173,10 +190,10 @@ public class BusService {
173190 }
174191
175192 // routeno 리스트 추출
176- List <String > busNames = result .getResponse ().getBody ().getItems ().getItem ().stream ()
177- .map (BusInfosDto . Item :: getRouteNo ). toList ();
178- System . out . println ( "bus names: " + busNames );
179- return busNames ;
193+ List <BusNameAndTypeResponse > list = result .getResponse ().getBody ().getItems ().getItem ().stream ()
194+ .map (i -> new BusNameAndTypeResponse ( i . getRouteNo (), i . getRouteTp (). substring ( 0 , 2 ))
195+ ). toList ( );
196+ return list ;
180197 }
181198
182199}
0 commit comments