Skip to content

Commit

Permalink
[FEAT] ApiClientException 추가 (#94)
Browse files Browse the repository at this point in the history
Closes #93
  • Loading branch information
JuneParkCode authored Aug 20, 2024
1 parent 64cfcca commit 4a582a7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
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

0 comments on commit 4a582a7

Please sign in to comment.