Skip to content

Commit

Permalink
🐛 실시간 열차 도착 정보 조회 API 버그 수정 (#342) (#344)
Browse files Browse the repository at this point in the history
* 🐛 열차 API 응답이 상행/하행 각각 한개씩 오는 경우 핸들링 (#342)

* 🐛 서킷 브레이커 fallback 메서드 찾을 수 없는 에러 해결 (#342)
  • Loading branch information
semi-cloud authored Feb 21, 2025
1 parent 57e62cf commit ca3f791
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ class TrainService(

val trainRealTimes = trainRealTimeMap.getOrElse(subwayLineIdentity.toString()) { emptyList() }

return upDownType?.let { type ->
trainRealTimes.filter { it.upDownType == type }.take(4)
return upDownType?.let {
type -> trainRealTimes.filter { it.upDownType == type }.take(4)
} ?: trainRealTimes
}

/**
* Redis 통신 오류에 대한 FallBack 메서드
*/
fun fallbackOnExternalTrainApiGet(
stationId: Long, subwayLineId: Long, e: RedisConnectionFailureException
stationId: Long, subwayLineId: Long, upDownType: UpDownType?, e: RedisConnectionFailureException
): List<GetTrainRealTimesDto.TrainRealTime> {
logger.error("can't connect to redis server")
throw CommonException(ResponseCode.FAILED_TO_CONNECT_TO_REDIS, e)
Expand All @@ -104,7 +104,7 @@ class TrainService(
* 열차 도착 정보 API 오류에 대한 FallBack 메서드
*/
fun fallbackOnExternalTrainApiGet(
stationId: Long, subwayLineId: Long, e : CallNotPermittedException
stationId: Long, subwayLineId: Long, upDownType: UpDownType?, e : CallNotPermittedException
): List<GetTrainRealTimesDto.TrainRealTime> {
logger.error("circuit breaker opened for external train api")
throw CommonException(ResponseCode.FAILED_TO_GET_TRAIN_INFO, e)
Expand Down Expand Up @@ -140,12 +140,16 @@ class TrainService(
trainRealTime
?.groupBy { it.updnLine }
?.entries?.forEach { map ->
val lis = map.value.map { dto ->
GetTrainRealTimesDto.TrainRealTime.of(dto, extractStationOrder(dto.arvlMsg2)) }
.sortedWith( compareBy(
{ it.currentTrainArrivalCode.priority },
{ it.stationOrder }
)).subList(0, 2)
val subIdx = if (map.value.size >= 2) 2 else 1 // 상행, 하행 각각 최대 두개씩 반환

val lis = map.value
.map { dto ->
GetTrainRealTimesDto.TrainRealTime.of(dto, extractStationOrder(dto.arvlMsg2))
}.sortedWith( compareBy(
{ it.currentTrainArrivalCode.priority },
{ it.stationOrder }
)).subList(0, subIdx)

total.addAll(lis)
}
return total
Expand Down

0 comments on commit ca3f791

Please sign in to comment.