|
6 | 6 | import com.example.busnotice.domain.busStop.res.BusStopsDto.Item; |
7 | 7 | import com.example.busnotice.domain.busStop.res.BusStopsDto.Items; |
8 | 8 | import com.example.busnotice.domain.busStop.res.SeoulBusStopsDto; |
| 9 | +import com.example.busnotice.global.code.ErrorCode; |
9 | 10 | import com.example.busnotice.global.code.StatusCode; |
10 | 11 | import com.example.busnotice.global.exception.BusStopException; |
11 | 12 | import com.example.busnotice.global.exception.GeneralException; |
|
16 | 17 | import java.net.URI; |
17 | 18 | import java.net.URLEncoder; |
18 | 19 | import java.nio.charset.StandardCharsets; |
| 20 | +import java.util.Collections; |
19 | 21 | import java.util.List; |
20 | 22 | import lombok.RequiredArgsConstructor; |
21 | 23 | import lombok.extern.slf4j.Slf4j; |
@@ -75,19 +77,19 @@ public class BusStopService { |
75 | 77 | } |
76 | 78 | String cityCode = result.toString().trim(); |
77 | 79 | if (cityCode == null || cityCode.isEmpty()) { |
78 | | - throw new GeneralException(StatusCode.BAD_REQUEST, "도시 코드 조회에 실패했습니다."); |
| 80 | + throw new GeneralException(ErrorCode.CITY_CODE_NOT_FOUND); |
79 | 81 | } |
80 | 82 | return result.toString().trim(); |
81 | 83 | } catch (Exception e) { |
82 | 84 | e.printStackTrace(); |
83 | | - throw new GeneralException(StatusCode.INTERNAL_SERVER_ERROR, "도시 코드 조회에 실패했습니다."); |
| 85 | + throw new GeneralException(ErrorCode.CITY_CODE_NOT_FOUND); |
84 | 86 | } |
85 | 87 | } |
86 | 88 |
|
87 | 89 | @Cacheable(value = "cityCodes", key = "#p0") |
88 | 90 | public String 도시코드_DB_조회(String cityName) { |
89 | 91 | String cityCode = cityCodeRepository.findByName(cityName.trim()) |
90 | | - .orElseThrow(() -> new GeneralException(StatusCode.BAD_REQUEST, "해당 지역이 존재하지 않습니다.")) |
| 92 | + .orElseThrow(() -> new GeneralException(ErrorCode.CITY_CODE_NOT_FOUND)) |
91 | 93 | .getCode(); |
92 | 94 |
|
93 | 95 | return cityCode; |
@@ -116,7 +118,7 @@ public class BusStopService { |
116 | 118 | System.out.println("response.toString() = " + response.toString()); |
117 | 119 | if (response.getMsgBody().getItemList() == null || response.getMsgBody().getItemList() |
118 | 120 | .isEmpty()) { |
119 | | - throw new BusStopException(StatusCode.NOT_FOUND, "해당 이름을 포함하는 버스정류장이 존재하지 않습니다."); |
| 121 | + return Collections.emptyList(); |
120 | 122 | } |
121 | 123 | List<String> busNames = response.getMsgBody().getItemList().stream() |
122 | 124 | .map(item -> item.getStNm()).toList(); |
@@ -147,7 +149,7 @@ public class BusStopService { |
147 | 149 | System.out.println("result.toString() = " + result.toString()); |
148 | 150 | Items items = result.getResponse().getBody().getItems(); |
149 | 151 | if (items == null || items.getItem().isEmpty()) { |
150 | | - throw new BusStopException(StatusCode.NOT_FOUND, "해당 이름을 포함하는 버스정류장이 존재하지 않습니다."); |
| 152 | + return Collections.emptyList(); |
151 | 153 | } |
152 | 154 | List<Item> itemsList = items.getItem(); |
153 | 155 | return itemsList.stream().map(item -> item.getNodenm()).toList(); |
@@ -176,7 +178,7 @@ public class BusStopService { |
176 | 178 | System.out.println("response.toString() = " + response.toString()); |
177 | 179 | if (response.getMsgBody().getItemList() == null || response.getMsgBody().getItemList() |
178 | 180 | .isEmpty()) { |
179 | | - throw new BusStopException(StatusCode.NOT_FOUND, "해당 이름을 포함하는 버스정류장이 존재하지 않습니다."); |
| 181 | + return new BusInfosResponse(Collections.emptyList()); |
180 | 182 | } |
181 | 183 | List<BusInfoResponse> busInfoResponses = response.getMsgBody().getItemList().stream() |
182 | 184 | .map(item -> new BusInfoResponse(item.getStNm(), item.getArsId(), |
@@ -207,9 +209,11 @@ public class BusStopService { |
207 | 209 | .block(); |
208 | 210 | System.out.println("result.toString() = " + result.toString()); |
209 | 211 | Items items = result.getResponse().getBody().getItems(); |
| 212 | + // 해당 하는 버스정류장이 없는 경우 |
210 | 213 | if (items == null || items.getItem().isEmpty()) { |
211 | | - throw new BusStopException(StatusCode.NOT_FOUND, "해당 이름을 포함하는 버스정류장이 존재하지 않습니다."); |
| 214 | + return new BusInfosResponse(Collections.emptyList()); |
212 | 215 | } |
| 216 | + // 해당 하는 버스정류장이 존재하는 경우 |
213 | 217 | List<Item> itemsList = items.getItem(); |
214 | 218 | List<BusInfoResponse> busInfoResponses = itemsList.stream() |
215 | 219 | .map(item -> new BusInfoResponse(item.getNodenm(), item.getNodeid(), |
@@ -241,7 +245,7 @@ public class BusStopService { |
241 | 245 | System.out.println("response.toString() = " + response.toString()); |
242 | 246 | if (response.getMsgBody().getItemList() == null || response.getMsgBody().getItemList() |
243 | 247 | .isEmpty()) { |
244 | | - throw new BusStopException(StatusCode.NOT_FOUND, "해당 이름을 포함하는 버스정류장이 존재하지 않습니다."); |
| 248 | + throw new BusStopException(ErrorCode.BUS_STOP_NOT_FOUND); |
245 | 249 | } |
246 | 250 | String nodeId = response.getMsgBody().getItemList().get(0).getArsId(); |
247 | 251 | return nodeId; |
@@ -269,7 +273,7 @@ public class BusStopService { |
269 | 273 | System.out.println("result.toString() = " + result.toString()); |
270 | 274 | Items items = result.getResponse().getBody().getItems(); |
271 | 275 | if (items == null || items.getItem().isEmpty()) { |
272 | | - throw new BusStopException(StatusCode.NOT_FOUND, "해당 이름을 포함하는 버스정류장이 존재하지 않습니다."); |
| 276 | + throw new BusStopException(ErrorCode.BUS_STOP_NOT_FOUND); |
273 | 277 | } |
274 | 278 | List<Item> itemsList = items.getItem(); |
275 | 279 | return itemsList.get(0).getNodeid(); |
|
0 commit comments