Skip to content
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] ApiClientException 추가 #94

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.talkka.server.api.core.exception;

public class ApiClientException extends RuntimeException {
public ApiClientException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

import java.util.List;

import com.talkka.server.api.core.exception.ApiClientException;
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<BusRouteSearchBodyDto> getSearchedRouteInfo(String routeName) throws ApiClientException;

List<BusRouteInfoBodyDto> getRouteInfo(String apiRouteId);
List<BusRouteInfoBodyDto> getRouteInfo(String apiRouteId) throws ApiClientException;

List<BusRouteStationBodyDto> getRouteStationInfo(String apiRouteId);
List<BusRouteStationBodyDto> getRouteStationInfo(String apiRouteId) throws ApiClientException;

List<BusLocationBodyDto> getBusLocationInfo(String apiRouteId);
List<BusLocationBodyDto> getBusLocationInfo(String apiRouteId) throws ApiClientException;

// List<RouteBusStationArrivalInfoRespDto> getBusStationArrivalInfo(String routeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;

import com.talkka.server.api.core.exception.ApiClientException;
import com.talkka.server.api.datagg.config.BusApiKeyProperty;
import com.talkka.server.api.datagg.dto.BusLocationBodyDto;
import com.talkka.server.api.datagg.dto.BusLocationRespDto;
Expand All @@ -30,51 +31,67 @@ public class BusApiServiceImpl implements BusApiService {
private static final String host = "apis.data.go.kr";

@Override
public List<BusRouteSearchBodyDto> getSearchedRouteInfo(String keyword) {
public List<BusRouteSearchBodyDto> getSearchedRouteInfo(String keyword) throws ApiClientException {
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();
try {
URI uri = this.getOpenApiUri(path, params);
ResponseEntity<BusRouteSearchRespDto> resp = restTemplate.getForEntity(uri, BusRouteSearchRespDto.class);
return resp.getBody().msgBody();
} catch (Exception exception) {
throw new ApiClientException(exception.getMessage());
}
}

@Override
public List<BusRouteInfoBodyDto> getRouteInfo(String apiRouteId) {
public List<BusRouteInfoBodyDto> getRouteInfo(String apiRouteId) throws ApiClientException {
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();
try {
URI uri = this.getOpenApiUri(path, params);
ResponseEntity<BusRouteInfoRespDto> resp = restTemplate.getForEntity(uri, BusRouteInfoRespDto.class);
return resp.getBody().msgBody();
} catch (Exception exception) {
throw new ApiClientException(exception.getMessage());
}
}

@Override
public List<BusRouteStationBodyDto> getRouteStationInfo(String apiRouteId) {
public List<BusRouteStationBodyDto> getRouteStationInfo(String apiRouteId) throws ApiClientException {
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();
try {
URI uri = this.getOpenApiUri(path, params);
ResponseEntity<BusRouteStationRespDto> resp = restTemplate.getForEntity(uri, BusRouteStationRespDto.class);
return resp.getBody().msgBody();
} catch (Exception exception) {
throw new ApiClientException(exception.getMessage());
}
}

@Override
public List<BusLocationBodyDto> getBusLocationInfo(String apiRouteId) {
public List<BusLocationBodyDto> getBusLocationInfo(String apiRouteId) throws ApiClientException {
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();
try {
URI uri = this.getOpenApiUri(path, params);
ResponseEntity<BusLocationRespDto> resp = restTemplate.getForEntity(uri, BusLocationRespDto.class);
return resp.getBody().msgBody();
} catch (Exception exception) {
throw new ApiClientException(exception.getMessage());
}
}

// @Override
// public List<RouteBusStationArrivalInfoRespDto> getBusStationArrivalInfo(String routeId) {
// return null;
// }

private URI getOpenApiURI(String path, MultiValueMap<String, String> params) {
private URI getOpenApiUri(String path, MultiValueMap<String, String> params) {
final var builder = new DefaultUriBuilderFactory();
builder.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
return builder.builder()
Expand Down
Loading