From 089e6da31c3af3d21b898feeeb6592a7cb4d6b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=9D=B8=ED=99=94?= Date: Tue, 24 Dec 2024 01:30:59 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=BD=94=EB=A6=AC=EC=95=84=ED=85=8D=20?= =?UTF-8?q?=EC=8A=B9=EC=B0=A8=20=EC=8B=9C=EA=B0=84=20=EC=98=A4=ED=94=84?= =?UTF-8?q?=EC=85=8B=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 코리아텍 승차 시간의 기점과의 오차를 보정하도록 로직 수정 --- .../bus/dto/CityBusTimetableResponse.java | 50 +++++++++---------- .../bus/model/enums/CityBusDirection.java | 16 ++++-- .../bus/model/mongo/CityBusTimetable.java | 15 ++++++ .../koin/domain/bus/service/BusService.java | 43 +++++++++++----- 4 files changed, 81 insertions(+), 43 deletions(-) diff --git a/src/main/java/in/koreatech/koin/domain/bus/dto/CityBusTimetableResponse.java b/src/main/java/in/koreatech/koin/domain/bus/dto/CityBusTimetableResponse.java index 107a9fbbf..65018e9b9 100644 --- a/src/main/java/in/koreatech/koin/domain/bus/dto/CityBusTimetableResponse.java +++ b/src/main/java/in/koreatech/koin/domain/bus/dto/CityBusTimetableResponse.java @@ -5,11 +5,13 @@ import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import in.koreatech.koin.domain.bus.model.enums.CityBusDirection; import in.koreatech.koin.domain.bus.model.mongo.CityBusTimetable; import io.swagger.v3.oas.annotations.media.Schema; @@ -51,41 +53,39 @@ public record CityBusTimetableResponse( List busTimetables ) { - public static CityBusTimetableResponse from(CityBusTimetable timetable) { - return new CityBusTimetableResponse( - timetable.getUpdatedAt(), - BusInfo.from(timetable.getBusInfo()), - timetable.getBusTimetables().stream() - .map(BusTimetable::from) - .toList() - ); - } - @JsonNaming(SnakeCaseStrategy.class) - public record BusInfo( - Long number, - String departNode, - String arrivalNode - ) { - public static BusInfo from(CityBusTimetable.BusInfo busInfo) { + public record BusInfo(Long number, String departNode, String arrivalNode) { + + public static BusInfo of(Long busNumber, CityBusDirection direction) { return new BusInfo( - busInfo.getNumber(), - busInfo.getDepart(), - busInfo.getArrival() + busNumber, + direction.getDepartNode(), + direction.getApartNode() ); } } @JsonNaming(SnakeCaseStrategy.class) - public record BusTimetable( - String dayOfWeek, - List departInfo - ) { - public static BusTimetable from(CityBusTimetable.BusTimetable timetable) { + public record BusTimetable(String dayOfWeek, List departInfo) { + + public static BusTimetable of(Long busNumber, CityBusDirection direction, + CityBusTimetable.BusTimetable timetable) { return new BusTimetable( timetable.getDayOfWeek(), - timetable.getDepartInfo() + timetable.applyTimeOffset(busNumber, direction).stream() + .map(LocalTime::toString) + .toList() ); } } + + public static CityBusTimetableResponse of(Long busNumber, CityBusDirection direction, CityBusTimetable timetable) { + return new CityBusTimetableResponse( + timetable.getUpdatedAt(), + BusInfo.of(busNumber, direction), + timetable.getBusTimetables().stream() + .map(busTimetable -> BusTimetable.of(busNumber, direction, busTimetable)) + .toList() + ); + } } diff --git a/src/main/java/in/koreatech/koin/domain/bus/model/enums/CityBusDirection.java b/src/main/java/in/koreatech/koin/domain/bus/model/enums/CityBusDirection.java index 0c020d82e..8571f62d7 100644 --- a/src/main/java/in/koreatech/koin/domain/bus/model/enums/CityBusDirection.java +++ b/src/main/java/in/koreatech/koin/domain/bus/model/enums/CityBusDirection.java @@ -5,13 +5,19 @@ import com.fasterxml.jackson.annotation.JsonCreator; import in.koreatech.koin.domain.bus.exception.BusTypeNotFoundException; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +@RequiredArgsConstructor +@Getter public enum CityBusDirection { - 종합터미널, - 병천3리, - 황사동, - 유관순열사사적지 - ; + 종합터미널("코리아텍", "천안 터미널"), + 병천3리("천안 터미널", "코리아텍"), + 황사동("천안 터미널", "코리아텍"), + 유관순열사사적지("천안 터미널", "코리아텍"); + + private final String departNode; + private final String apartNode; @JsonCreator public static CityBusDirection from(String direction) { diff --git a/src/main/java/in/koreatech/koin/domain/bus/model/mongo/CityBusTimetable.java b/src/main/java/in/koreatech/koin/domain/bus/model/mongo/CityBusTimetable.java index 5096fe355..dfc1c87f5 100644 --- a/src/main/java/in/koreatech/koin/domain/bus/model/mongo/CityBusTimetable.java +++ b/src/main/java/in/koreatech/koin/domain/bus/model/mongo/CityBusTimetable.java @@ -6,6 +6,7 @@ import java.time.LocalTime; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.springframework.data.mongodb.core.mapping.Document; @@ -13,6 +14,7 @@ import in.koreatech.koin.domain.bus.dto.BusScheduleResponse.ScheduleInfo; import in.koreatech.koin.domain.bus.model.enums.BusStation; +import in.koreatech.koin.domain.bus.model.enums.CityBusDirection; import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Builder; @@ -126,5 +128,18 @@ public List applyTimeOffset(Long busNumber, BusStation depart) { }) .collect(Collectors.toList()); } + + public List applyTimeOffset(Long busNumber, CityBusDirection direction) { + Map> timeOffsets = Map.of( + 400L, Map.of(CityBusDirection.종합터미널, ADDITIONAL_TIME_DEPART_TO_KOREATECH_400), + 402L, Map.of(CityBusDirection.종합터미널, ADDITIONAL_TIME_DEPART_TO_KOREATECH_402), + 405L, Map.of(CityBusDirection.종합터미널, ADDITIONAL_TIME_DEPART_TO_KOREATECH_405) + ); + int offset = timeOffsets.getOrDefault(busNumber, Map.of()) + .getOrDefault(direction, 0); + return departInfo.stream() + .map(time -> LocalTime.parse(time).plusMinutes(offset)) + .collect(Collectors.toList()); + } } } diff --git a/src/main/java/in/koreatech/koin/domain/bus/service/BusService.java b/src/main/java/in/koreatech/koin/domain/bus/service/BusService.java index f080681a5..456c9ae9a 100644 --- a/src/main/java/in/koreatech/koin/domain/bus/service/BusService.java +++ b/src/main/java/in/koreatech/koin/domain/bus/service/BusService.java @@ -1,7 +1,33 @@ package in.koreatech.koin.domain.bus.service; -import in.koreatech.koin.domain.bus.dto.*; +import static in.koreatech.koin.domain.bus.model.enums.BusStation.getDirection; + +import java.time.Clock; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; +import java.time.format.TextStyle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import in.koreatech.koin.domain.bus.dto.BusCourseResponse; +import in.koreatech.koin.domain.bus.dto.BusNoticeResponse; +import in.koreatech.koin.domain.bus.dto.BusRemainTimeResponse; +import in.koreatech.koin.domain.bus.dto.BusRouteCommand; +import in.koreatech.koin.domain.bus.dto.BusScheduleResponse; import in.koreatech.koin.domain.bus.dto.BusScheduleResponse.ScheduleInfo; +import in.koreatech.koin.domain.bus.dto.BusTimetableResponse; +import in.koreatech.koin.domain.bus.dto.CityBusTimetableResponse; +import in.koreatech.koin.domain.bus.dto.SingleBusTimeResponse; import in.koreatech.koin.domain.bus.exception.BusIllegalStationException; import in.koreatech.koin.domain.bus.exception.BusTypeNotFoundException; import in.koreatech.koin.domain.bus.exception.BusTypeNotSupportException; @@ -26,14 +52,6 @@ import in.koreatech.koin.domain.version.service.VersionService; import in.koreatech.koin.global.exception.KoinIllegalArgumentException; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.*; -import java.time.format.TextStyle; -import java.util.*; - -import static in.koreatech.koin.domain.bus.model.enums.BusStation.getDirection; @Service @Transactional(readOnly = true) @@ -218,8 +236,7 @@ public List getBusCourses() { public CityBusTimetableResponse getCityBusTimetable(Long busNumber, CityBusDirection direction) { CityBusTimetable timetable = cityBusTimetableRepository .getByBusInfoNumberAndBusInfoArrival(busNumber, direction.getName()); - - return CityBusTimetableResponse.from(timetable); + return CityBusTimetableResponse.of(busNumber, direction, timetable); } public BusScheduleResponse getBusSchedule(BusRouteCommand request) { @@ -250,8 +267,8 @@ public BusNoticeResponse getNotice() { } return BusNoticeResponse.of( - (Integer) article.get("id"), - (String) article.get("title") + (Integer)article.get("id"), + (String)article.get("title") ); } }