-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 버스 교통편 조회 API
- Loading branch information
Showing
17 changed files
with
539 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/in/koreatech/koin/domain/bus/dto/BusRouteCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package in.koreatech.koin.domain.bus.dto; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
import in.koreatech.koin.domain.bus.model.enums.BusRouteType; | ||
import in.koreatech.koin.domain.bus.model.enums.BusStation; | ||
|
||
public record BusRouteCommand( | ||
|
||
BusStation depart, | ||
BusStation arrive, | ||
BusRouteType busRouteType, | ||
LocalDate date, | ||
LocalTime time | ||
) { | ||
|
||
public boolean checkAvailableCourse() { | ||
return depart != arrive; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/in/koreatech/koin/domain/bus/dto/BusScheduleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package in.koreatech.koin.domain.bus.dto; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED; | ||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import in.koreatech.koin.domain.bus.model.enums.BusStation; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@JsonNaming(SnakeCaseStrategy.class) | ||
public record BusScheduleResponse( | ||
@Schema(description = "출발 정류장", example = "KOREATECH", requiredMode = REQUIRED) | ||
BusStation depart, | ||
@Schema(description = "도착 정류장", example = "TERMINAL", requiredMode = REQUIRED) | ||
BusStation arrival, | ||
@Schema(description = "출발 날짜", example = "2024-11-05", requiredMode = REQUIRED) | ||
LocalDate departDate, | ||
@Schema(description = "출발 시간", example = "12:00", requiredMode = REQUIRED) | ||
LocalTime departTime, | ||
@Schema(description = "교통편 조회 결과", requiredMode = NOT_REQUIRED) | ||
List<ScheduleInfo> schedule | ||
|
||
) { | ||
@JsonNaming(SnakeCaseStrategy.class) | ||
public record ScheduleInfo( | ||
@Schema(description = "버스 타입 (shuttle, express, city)", example = "express", requiredMode = REQUIRED) | ||
String busType, | ||
@Schema(description = "버스 이름 또는 노선명", example = "대성티앤이", requiredMode = REQUIRED) | ||
String busName, | ||
@Schema(description = "버스 출발 시간", example = "16:50", requiredMode = REQUIRED) | ||
LocalTime departTime | ||
) { | ||
|
||
public static Comparator<ScheduleInfo> compareBusType() { | ||
List<String> priority = List.of("shuttle", "express", "city"); | ||
return Comparator.comparingInt(schedule -> priority.indexOf(schedule.busType)); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/in/koreatech/koin/domain/bus/model/enums/BusRouteType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package in.koreatech.koin.domain.bus.model.enums; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
|
||
import in.koreatech.koin.domain.bus.exception.BusTypeNotFoundException; | ||
|
||
public enum BusRouteType { | ||
CITY, | ||
EXPRESS, | ||
SHUTTLE, | ||
ALL; | ||
|
||
@JsonCreator | ||
public static BusRouteType from(String busRouteTypeName) { | ||
return Arrays.stream(values()) | ||
.filter(busType -> busType.name().equalsIgnoreCase(busRouteTypeName)) | ||
.findAny() | ||
.orElseThrow(() -> BusTypeNotFoundException.withDetail("busRouteTypeName: " + busRouteTypeName)); | ||
} | ||
|
||
public String getName() { | ||
return this.name().toLowerCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/in/koreatech/koin/domain/bus/model/express/ExpressBusSchedule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package in.koreatech.koin.domain.bus.model.express; | ||
|
||
import java.time.LocalTime; | ||
import java.util.List; | ||
|
||
/** | ||
* 한기대와 천안터미널 사이를 운행하는 대성 고속버스의 운행 스케줄을 정적인 데이터로 저장한 클래스입니다. | ||
* 외부 API 가 동작하지 않는 이슈의 해결 전까지 임시적으로 사용하기 위해 작성되었습니다. | ||
*/ | ||
public final class ExpressBusSchedule { | ||
|
||
/** | ||
* 천안 터미널 -> 한기대 출발 시간 | ||
*/ | ||
private static final List<LocalTime> KOREA_TECH_SCHEDULE = List.of( | ||
LocalTime.of(7, 0), | ||
LocalTime.of(8, 30), | ||
LocalTime.of(9, 0), | ||
LocalTime.of(10, 0), | ||
LocalTime.of(12, 0), | ||
LocalTime.of(12, 30), | ||
LocalTime.of(13, 0), | ||
LocalTime.of(15, 0), | ||
LocalTime.of(16, 0), | ||
LocalTime.of(16, 40), | ||
LocalTime.of(18, 0), | ||
LocalTime.of(19, 30), | ||
LocalTime.of(20, 30) | ||
); | ||
|
||
/** | ||
* 한기대 -> 천안 터미널 출발 시간 | ||
*/ | ||
private static final List<LocalTime> TERMINAL_SCHEDULE = List.of( | ||
LocalTime.of(8, 35), | ||
LocalTime.of(10, 35), | ||
LocalTime.of(11, 5), | ||
LocalTime.of(11, 35), | ||
LocalTime.of(13, 35), | ||
LocalTime.of(14, 35), | ||
LocalTime.of(15, 5), | ||
LocalTime.of(16, 35), | ||
LocalTime.of(17, 35), | ||
LocalTime.of(19, 5), | ||
LocalTime.of(19, 35), | ||
LocalTime.of(21, 5), | ||
LocalTime.of(22, 5) | ||
); | ||
|
||
public static List<LocalTime> getExpressBusScheduleToKoreaTech() { | ||
return KOREA_TECH_SCHEDULE; | ||
} | ||
|
||
public static List<LocalTime> getExpressBusScheduleToTerminal() { | ||
return TERMINAL_SCHEDULE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.