-
Notifications
You must be signed in to change notification settings - Fork 2
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] BusApiService 구현 #62
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions
5
server/src/main/java/com/talkka/server/api/core/config/ApiKeyProperty.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,5 @@ | ||
package com.talkka.server.api.core.config; | ||
|
||
public interface ApiKeyProperty { | ||
String getApiKey(); | ||
} |
27 changes: 27 additions & 0 deletions
27
server/src/main/java/com/talkka/server/api/datagg/config/BusApiKeyProperty.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,27 @@ | ||
package com.talkka.server.api.datagg.config; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.talkka.server.api.core.config.ApiKeyProperty; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Component | ||
@ConfigurationProperties(prefix = "openapi.public.bus.service-key") | ||
public class BusApiKeyProperty implements ApiKeyProperty { | ||
@Setter | ||
private List<String> keys; | ||
|
||
private int rollingKeyIndex = 0; | ||
|
||
@Override | ||
public String getApiKey() { | ||
rollingKeyIndex = (rollingKeyIndex + 1) % keys.size(); | ||
return keys.get(rollingKeyIndex); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationBodyDto.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,8 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
@JacksonXmlRootElement(localName = "busLocationList") | ||
public record BusLocationBodyDto(String endBus, String lowPlate, String plateNo, String plateType, | ||
Integer remainSeatCnt, Long routeId, Long stationId, Integer stationSeq) { | ||
} |
14 changes: 14 additions & 0 deletions
14
server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationRespDto.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,14 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
@JacksonXmlRootElement(localName = "response") | ||
public record BusLocationRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map<String, String> comMsgHeader, | ||
@JacksonXmlProperty(localName = "msgHeader") Map<String, String> msgHeader, | ||
@JacksonXmlProperty(localName = "msgBody") List<BusLocationBodyDto> msgBody) | ||
implements PublicBusApiResp<BusLocationBodyDto> { | ||
} |
28 changes: 28 additions & 0 deletions
28
server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoBodyDto.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,28 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
@JacksonXmlRootElement(localName = "busRouteInfoItem") | ||
public record BusRouteInfoBodyDto( | ||
String companyId, // 운수업체 아이디 | ||
String companyName, // 운수업체명 | ||
String companyTel, // 운수업체 전화번호 | ||
int districtCd, // 관할 지역 코드 | ||
String downFirstTime, // 평일 종점 첫차 시간 | ||
String downLastTime, // 평일 종점 막차 시간 | ||
Long endStationId, // 종점 정류소 아이디 | ||
String endStationName, // 종점 정류소명 | ||
int peekAlloc, // 평일 최소 배차 시간 | ||
String regionName, // 지역명 | ||
Long routeId, // 노선 아이디 | ||
String routeName, // 노선 번호 | ||
int routeTypeCd, // 노선 유형 코드 | ||
String routeTypeName, // 노선 유형명 | ||
String startMobileNo, // 기점 정류소 번호 | ||
Long startStationId, // 기점 정류소 아이디 | ||
String startStationName, // 기점 정류소명 | ||
String upFirstTime, // 평일 기점 첫차 시간 | ||
String upLastTime, // 평일 기점 막차 시간 | ||
int nPeekAlloc // 평일 최대 배차 시간 | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoRespDto.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,14 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
@JacksonXmlRootElement(localName = "response") | ||
public record BusRouteInfoRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map<String, String> comMsgHeader, | ||
@JacksonXmlProperty(localName = "msgHeader") Map<String, String> msgHeader, | ||
@JacksonXmlProperty(localName = "msgBody") List<BusRouteInfoBodyDto> msgBody) | ||
implements PublicBusApiResp<BusRouteInfoBodyDto> { | ||
} |
15 changes: 15 additions & 0 deletions
15
server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchBodyDto.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,15 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
/** | ||
* @param routeId 노선 아이디 | ||
* @param routeName 노선 번호 | ||
* @param routeTypeCd 노선 유형 코드 | ||
* @param routeTypeName 노선 유형명 | ||
* @param regionName 노선 운행 지역 | ||
* @param districtCd 노선 관할 지역 코드 */ | ||
@JacksonXmlRootElement(localName = "busRouteList") | ||
public record BusRouteSearchBodyDto(Long routeId, String routeName, String routeTypeCd, String routeTypeName, | ||
String regionName, int districtCd) { | ||
} |
14 changes: 14 additions & 0 deletions
14
server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchRespDto.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,14 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
@JacksonXmlRootElement(localName = "response") | ||
public record BusRouteSearchRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map<String, String> comMsgHeader, | ||
@JacksonXmlProperty(localName = "msgHeader") Map<String, String> msgHeader, | ||
@JacksonXmlProperty(localName = "msgBody") List<BusRouteSearchBodyDto> msgBody) | ||
implements PublicBusApiResp<BusRouteSearchBodyDto> { | ||
} |
20 changes: 20 additions & 0 deletions
20
server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationBodyDto.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,20 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
/** | ||
* @param stationId 정류소 아이디 | ||
* @param stationSeq 정류소 순번 | ||
* @param stationName 정류소 명칭 | ||
* @param mobileNo 정류소 고유 모바일 번호 | ||
* @param regionName 정류소 위치 지역명 | ||
* @param districtCd 노선 관할 지역 코드 | ||
* @param centerYn 중앙차로 여부 (N: 일반, Y: 중앙차로) | ||
* @param turnYn 회차점 여부 (N: 일반, Y: 회차점) | ||
* @param x 정류소 X 좌표 | ||
* @param y 정류소 Y 좌표 */ | ||
@JacksonXmlRootElement(localName = "busRouteStationList") | ||
public record BusRouteStationBodyDto(Long stationId, Integer stationSeq, String stationName, String mobileNo, | ||
String regionName, String districtCd, String centerYn, String turnYn, Double x, | ||
Double y) { | ||
} |
14 changes: 14 additions & 0 deletions
14
server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationRespDto.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,14 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
@JacksonXmlRootElement(localName = "response") | ||
public record BusRouteStationRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map<String, String> comMsgHeader, | ||
@JacksonXmlProperty(localName = "msgHeader") Map<String, String> msgHeader, | ||
@JacksonXmlProperty(localName = "msgBody") List<BusRouteStationBodyDto> msgBody) | ||
implements PublicBusApiResp<BusRouteStationBodyDto> { | ||
} |
12 changes: 12 additions & 0 deletions
12
server/src/main/java/com/talkka/server/api/datagg/dto/PublicBusApiResp.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,12 @@ | ||
package com.talkka.server.api.datagg.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface PublicBusApiResp<T> { | ||
Map<String, String> comMsgHeader(); | ||
|
||
Map<String, String> msgHeader(); | ||
|
||
List<T> msgBody(); | ||
} |
20 changes: 20 additions & 0 deletions
20
server/src/main/java/com/talkka/server/api/datagg/service/BusApiService.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,20 @@ | ||
package com.talkka.server.api.datagg.service; | ||
|
||
import java.util.List; | ||
|
||
import com.talkka.server.api.datagg.dto.BusLocationBodyDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteInfoBodyDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteSearchBodyDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteStationBodyDto; | ||
|
||
public interface BusApiService { | ||
List<BusRouteSearchBodyDto> getSearchedRouteInfo(String routeName); | ||
|
||
List<BusRouteInfoBodyDto> getRouteInfo(String apiRouteId); | ||
|
||
List<BusRouteStationBodyDto> getRouteStationInfo(String apiRouteId); | ||
|
||
List<BusLocationBodyDto> getBusLocationInfo(String apiRouteId); | ||
|
||
// List<RouteBusStationArrivalInfoRespDto> getBusStationArrivalInfo(String routeId); | ||
} |
88 changes: 88 additions & 0 deletions
88
server/src/main/java/com/talkka/server/api/datagg/service/BusApiServiceImpl.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,88 @@ | ||
package com.talkka.server.api.datagg.service; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.DefaultUriBuilderFactory; | ||
|
||
import com.talkka.server.api.datagg.config.BusApiKeyProperty; | ||
import com.talkka.server.api.datagg.dto.BusLocationBodyDto; | ||
import com.talkka.server.api.datagg.dto.BusLocationRespDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteInfoBodyDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteInfoRespDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteSearchBodyDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteSearchRespDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteStationBodyDto; | ||
import com.talkka.server.api.datagg.dto.BusRouteStationRespDto; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BusApiServiceImpl implements BusApiService { | ||
private final BusApiKeyProperty busApiKeyProperty; | ||
private final RestTemplate restTemplate = new RestTemplate(); | ||
private static final String host = "apis.data.go.kr"; | ||
|
||
@Override | ||
public List<BusRouteSearchBodyDto> getSearchedRouteInfo(String keyword) { | ||
final String path = "/6410000/busrouteservice/getBusRouteList"; | ||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||
params.add("keyword", keyword); | ||
URI uri = this.getOpenApiURI(path, params); | ||
ResponseEntity<BusRouteSearchRespDto> resp = restTemplate.getForEntity(uri, BusRouteSearchRespDto.class); | ||
return resp.getBody().msgBody(); | ||
} | ||
|
||
@Override | ||
public List<BusRouteInfoBodyDto> getRouteInfo(String apiRouteId) { | ||
final String path = "/6410000/busrouteservice/getBusRouteInfoItem"; | ||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||
params.add("routeId", apiRouteId); | ||
URI uri = this.getOpenApiURI(path, params); | ||
ResponseEntity<BusRouteInfoRespDto> resp = restTemplate.getForEntity(uri, BusRouteInfoRespDto.class); | ||
return resp.getBody().msgBody(); | ||
} | ||
|
||
@Override | ||
public List<BusRouteStationBodyDto> getRouteStationInfo(String apiRouteId) { | ||
final String path = "/6410000/busrouteservice/getBusRouteStationList"; | ||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||
params.add("routeId", apiRouteId); | ||
URI uri = this.getOpenApiURI(path, params); | ||
ResponseEntity<BusRouteStationRespDto> resp = restTemplate.getForEntity(uri, BusRouteStationRespDto.class); | ||
return resp.getBody().msgBody(); | ||
} | ||
|
||
@Override | ||
public List<BusLocationBodyDto> getBusLocationInfo(String apiRouteId) { | ||
final String path = "/6410000/buslocationservice/getBusLocationList"; | ||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||
params.add("routeId", apiRouteId); | ||
URI uri = this.getOpenApiURI(path, params); | ||
ResponseEntity<BusLocationRespDto> resp = restTemplate.getForEntity(uri, BusLocationRespDto.class); | ||
return resp.getBody().msgBody(); | ||
} | ||
|
||
// @Override | ||
// public List<RouteBusStationArrivalInfoRespDto> getBusStationArrivalInfo(String routeId) { | ||
// return null; | ||
// } | ||
|
||
private URI getOpenApiURI(String path, MultiValueMap<String, String> params) { | ||
final var builder = new DefaultUriBuilderFactory(); | ||
builder.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE); | ||
return builder.builder() | ||
.scheme("https") | ||
.host(host) | ||
.path(path) | ||
.queryParam("serviceKey", this.busApiKeyProperty.getApiKey()) | ||
.queryParams(params) | ||
.build(); | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
프론트 작업을 위해 임시로 구현해두신게 맞을까요?
api 통신 쪽을 별도 인터페이스로 분리하기로 했던것같아서..
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.
맞습니다. interface 로 분리해둔 곳이 BusApiService 이고, 이를 가볍게 구현해둔 곳이 Impl 부분입니다.