|
2 | 2 |
|
3 | 3 | import koreatech.in.domain.Bus.*; |
4 | 4 | import koreatech.in.domain.ErrorMessage; |
| 5 | +import koreatech.in.domain.Version.Version; |
| 6 | +import koreatech.in.dto.normal.bus.BusTimetableResponse; |
| 7 | +import koreatech.in.exception.BaseException; |
| 8 | +import koreatech.in.exception.ExceptionInformation; |
5 | 9 | import koreatech.in.exception.PreconditionFailedException; |
6 | 10 | import koreatech.in.mapstruct.normal.bus.SchoolBusCourseConverter; |
7 | 11 | import koreatech.in.repository.BusRepository; |
| 12 | +import koreatech.in.repository.VersionMapper; |
| 13 | + |
8 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
9 | 15 | import org.springframework.stereotype.Service; |
10 | 16 | import org.springframework.util.StringUtils; |
|
16 | 22 | import java.util.ArrayList; |
17 | 23 | import java.util.List; |
18 | 24 | import java.util.Objects; |
| 25 | +import java.util.Optional; |
19 | 26 |
|
20 | 27 | @Service |
21 | 28 | public class BusServiceImpl implements BusService { |
22 | 29 |
|
23 | 30 | @Autowired |
24 | 31 | private BusRepository busRepository; |
25 | 32 |
|
| 33 | + @Autowired |
| 34 | + private VersionMapper versionMapper; |
| 35 | + |
26 | 36 | @Override |
27 | 37 | public BusRemainTime getRemainTime(String busType, String depart, String arrival) { |
28 | 38 |
|
@@ -81,4 +91,21 @@ public List<SingleBusTime> searchTimetable(String date, String time, String depa |
81 | 91 |
|
82 | 92 | return result; |
83 | 93 | } |
| 94 | + |
| 95 | + @Override |
| 96 | + public BusTimetableResponse getTimetableWithUpdatedAt(String busType, String direction, String region) { |
| 97 | + List<? extends BusTimetable> busTimetables = getTimetable(busType, direction, region); |
| 98 | + |
| 99 | + if (busType.equalsIgnoreCase("commuting")) { |
| 100 | + busType = "shuttle"; |
| 101 | + } |
| 102 | + |
| 103 | + Version version = Optional.ofNullable(versionMapper.getVersion(busType + "_bus_timetable")) |
| 104 | + .orElseThrow(() -> new BaseException(ExceptionInformation.VERSION_NOT_FOUND)); |
| 105 | + |
| 106 | + return BusTimetableResponse.builder() |
| 107 | + .busTimetables(busTimetables) |
| 108 | + .updatedAt(version.getUpdated_at()) |
| 109 | + .build(); |
| 110 | + } |
84 | 111 | } |
0 commit comments