Skip to content

Commit

Permalink
fix: 코리아텍 승차 시간 오프셋 설정
Browse files Browse the repository at this point in the history
코리아텍 승차 시간의 기점과의 오차를 보정하도록 로직 수정
  • Loading branch information
kih1015 committed Dec 23, 2024
1 parent 2508fc1 commit 089e6da
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,41 +53,39 @@ public record CityBusTimetableResponse(
List<BusTimetable> 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<String> departInfo
) {
public static BusTimetable from(CityBusTimetable.BusTimetable timetable) {
public record BusTimetable(String dayOfWeek, List<String> 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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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;
import org.springframework.data.mongodb.core.mapping.Field;

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;
Expand Down Expand Up @@ -126,5 +128,18 @@ public List<LocalTime> applyTimeOffset(Long busNumber, BusStation depart) {
})
.collect(Collectors.toList());
}

public List<LocalTime> applyTimeOffset(Long busNumber, CityBusDirection direction) {
Map<Long, Map<CityBusDirection, Integer>> 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());
}
}
}
43 changes: 30 additions & 13 deletions src/main/java/in/koreatech/koin/domain/bus/service/BusService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -218,8 +236,7 @@ public List<BusCourseResponse> 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) {
Expand Down Expand Up @@ -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")
);
}
}

0 comments on commit 089e6da

Please sign in to comment.