-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 버스 교통편 조회 API #1099
feat: 버스 교통편 조회 API #1099
Changes from all commits
f9c9d8d
f62e322
c138c80
70e5b38
180f899
8f487af
fa05713
ab7e344
cd81e3b
69ed6b8
e8f80cf
552b763
65a66b9
fca0a90
bb908b5
a8646e4
475534c
ef1ef9e
187fbd2
0552b56
031e938
2c4291b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Crequest dto 용도의 클래스를 만들어야 한다면 차라리 GET요청이지만 request body를 사용하는 건 어떻게 생각하시나요?? 기능에 비해 복잡도가 커지는 것 같아서 우려되네요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 파라미터로 받은 내용들을 다시 전부 단일 record로 묶어서 service를 호출하길래 get 요청에 body를 담지 않으려고 이렇게 한건가? 했습니다. 그런 구조였다면 괜찮을 수도 있을 것 같네요 👍 |
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; | ||
} | ||
} |
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)); | ||
} | ||
} | ||
} |
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(); | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A주석으로 부연설명을 조금 달아두는 것도 좋을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 적용했습니다. |
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C
request와 response에서 모두 date와 time을 분리하여 전달하고 있는데, 분리해야 했던 이유가 있을까요?? 다른 곳에서는 대부분은 합쳐서 사용하고 있지 않나요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
디자인에 '오늘 오후 10:30 출발' 이런식으로 출력하도록 되어 있길래 분리 하는 게 클라이언트 입장에서 더 편할 것 같다고 생각했습니다. 버스 도메인 다른 API(버스 검색)도 저런 형태로 정보를 받고 있어서 그대로 진행했습니다.