개발일기
(2) OttDaDam 헌옷 수거함 공공 API 본문
공공 데이터 불러와서 해주는 부분의 코드 리팩토링을 조금 하였다.
public static List<String> selectApiLocation(String location,String openApiKey) throws URISyntaxException, ParseException {
switch (location)
{
case "guro":
openApiManagerDto = OpenApiManagerDto.builder()
.BaseUrl(API_URL)
.serviceKey(openApiKey)
.page(START_PAGE)
.perPage(END_PAGE)
.uddi("672059d4-1830-44af-97dd-cf0954b2ee86")
.locationNumber(15068871)
.build();
apiData = (ArrayList<String>) openApiManagerDto.getAllFetch();
break;
case "yangcheon" :
openApiManagerDto = OpenApiManagerDto.builder()
.BaseUrl(API_URL)
.serviceKey(openApiKey)
.page(START_PAGE)
.perPage(END_PAGE)
.uddi("ce842bd1-877f-41b0-b612-81bb77bdbb1d")
.locationNumber(15105196)
.build();
apiData = (ArrayList<String>) openApiManagerDto.getAllFetch();
break;
case "jongno" :
openApiManagerDto = OpenApiManagerDto.builder()
.BaseUrl(API_URL)
.serviceKey(openApiKey)
.page(START_PAGE)
.perPage(END_PAGE)
.uddi("94ddbdca-b180-4156-b4f0-8048116792f9")
.locationNumber(15104622)
.build();
apiData = (ArrayList<String>) openApiManagerDto.getAllFetch();
break;
case "gwanak" :
openApiManagerDto = OpenApiManagerDto.builder()
.BaseUrl(API_URL)
.serviceKey(openApiKey)
.page(START_PAGE)
.perPage(END_PAGE)
.uddi("6dec2a8d-6404-4318-8767-85419b3c45a0")
.locationNumber(15076398)
.build();
apiData = (ArrayList<String>) openApiManagerDto.getAllFetch();
break;
case "dongjak" :
openApiManagerDto = OpenApiManagerDto.builder()
.BaseUrl(API_URL)
.serviceKey(openApiKey)
.page(START_PAGE)
.perPage(END_PAGE)
.uddi("05be3e28-de40-426b-9198-e4ca5b3ceee7")
.locationNumber(15068021)
.build();
apiData = (ArrayList<String>) openApiManagerDto.getAllFetch();
break;
case "gwangjin" :
openApiManagerDto = OpenApiManagerDto.builder()
.BaseUrl(API_URL)
.serviceKey(openApiKey)
.page(START_PAGE)
.perPage(END_PAGE)
.uddi("d63e68bf-e03d-4d3c-a203-fd9add3d372c")
.locationNumber(15109594)
.build();
apiData = (ArrayList<String>) openApiManagerDto.getAllFetch();
break;
}
return apiData;
}
Builder패턴과 상수로 사용할 수 있을 만한 부분의 코드들은 빼주었다. 또한 Spring properties값을 설정해주어 API_KEY를 숨겨주었다.
각각의 중복되는 부분을 함수로 따로 빼줄까 고민중인데 해당 작업은 추후에 할 예정이다.
@Value("${data.apikey}")
private String openApiKey;
// URI형식의 OpenApiData형식을 가져온다.
public List<String> getOpenApiUriData() throws URISyntaxException, ParseException {
List<String> openApiUriList = new ArrayList<>();
String[] locations = {"guro","yangcheon","jongno","gwanak","dongjak","gwangjin"};
for(String location : locations){
openApiUriList.addAll(CmnUtil.selectApiLocation(location, openApiKey));
LOGGER.info("LOGGER::");
}
return openApiUriList;
}
openApiKey를 받을 수 있게 만들어주었다.
# openApiServiceKey
data.apikey = OpenApiServiceKey
application.properties 코드이다. OpenApiServiceKey 쪽에 공공데이터 키값을 넣어주면 된다.
'OttDaDam 서울시 헌옷수거함 project' 카테고리의 다른 글
백그라운드 React nohup으로 실행시키기 (1) | 2024.06.27 |
---|---|
AWS Springboot React 배포 (0) | 2023.11.11 |
(3) OttDaDam 프로젝트 DB 구축을 위한 Mac M1에서 MySql 설치 (0) | 2023.08.02 |
옷다담 환경 설정 에러 JAVA_HOME is set to an invalid directory: (2) | 2023.07.22 |
서울시 헌옷 수거함 개발일기 - 공공 데이터 API (1) (9) | 2023.07.21 |