Skip to content

Commit

Permalink
[#14] feat : 측정소 데이터를 전달하는 컨트롤러 구현
Browse files Browse the repository at this point in the history
- 가장 가까운 측정소 데이터중에 1번째값이 가장 가까운 측정소를 나타내기 때문에, 해당 측정소의 값을 컨트롤러에서 전달하도록 구현

#14

# --COMMIT END--
# <타입> 리스트
# feat : 기능 (새로운 기능)
# fix : 버그 (버그 수정)
# refactor : 리팩토링
# style : 스타일(코드 형식, 세미콜론 추가 : 비지니스 로직 변경 X)
# docs : 문서 (문서 추가, 수정, 삭제)
# test : 테스트 (테스트 코드 추가, 수정, 삭제 : 비지니스 로직 변경 X)
# chroe : 기타 변경사항(빌드 스크립트 수정 등)
-------------------------
#	제목 첫 글자 대문자
#	제목은 명령문
#	제목 끝에 마침표(.) 금지
#	제목과 본문을 한 줄 띄워 분리하기
#	본문은 "어떻게" 보다 "무엇을" , "왜"를 설명한다
#	본문에 여러줄의 메시지를 작성할 땐 "-"로 구분
-------------------------
  • Loading branch information
haveagood committed Apr 1, 2020
1 parent abdd724 commit cfb6714
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
46 changes: 31 additions & 15 deletions BE/src/main/java/com/codesquad/dust7/DailyDustResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,40 @@ public ArrayList<DailyAirCondition> dailyAirConditionParser() throws IOException
OpenApiGetData openApiGetData = new OpenApiGetData();
JSONArray dailyAirConditionData = openApiGetData.getAirCondition();
ArrayList<DailyAirCondition> parseDailyAirCondition = new ArrayList<>();
for (int i = 0; i < dailyAirConditionData.length(); i++) {
JSONObject oneAirData = dailyAirConditionData.getJSONObject(i);
String dataTime = oneAirData.get("dataTime").toString();
String imageUrl1 = oneAirData.get("imageUrl1").toString();
String imageUrl2 = oneAirData.get("imageUrl2").toString();
String imageUrl3 = oneAirData.get("imageUrl3").toString();
String informGrade = oneAirData.get("informGrade").toString();
String informCause = oneAirData.get("informCause").toString();
String informOverall = oneAirData.get("informOverall").toString();
DailyAirCondition dailyAirCondition = new DailyAirCondition(dataTime,imageUrl1,imageUrl2,imageUrl3,informGrade,informCause,informOverall);
parseDailyAirCondition.add(dailyAirCondition);
}

JSONObject oneAirData = dailyAirConditionData.getJSONObject(1);
String dataTime = oneAirData.get("dataTime").toString();
String imageUrl1 = oneAirData.get("imageUrl1").toString();
String imageUrl2 = oneAirData.get("imageUrl2").toString();
String imageUrl3 = oneAirData.get("imageUrl3").toString();
String gifFile = oneAirData.get("imageUrl7").toString();
String informGrade = oneAirData.get("informGrade").toString();
String informCause = oneAirData.get("informCause").toString();
String informOverall = oneAirData.get("informOverall").toString();
DailyAirCondition dailyAirCondition = new DailyAirCondition(dataTime,imageUrl1,imageUrl2,imageUrl3,gifFile,informGrade,informCause,informOverall);
parseDailyAirCondition.add(dailyAirCondition);

return parseDailyAirCondition;
}

public ArrayList<StationInformation> stationInformations(String coordinateWGS84) throws IOException, JSONException {
OpenApiGetData openApiGetData = new OpenApiGetData();

String coordX = coordinateWGS84.split(",")[0];
String coordY = coordinateWGS84.split(",")[1];

JSONObject transferResult = openApiGetData.kakaoTransferAPI(coordX,coordY);
JSONArray stations = openApiGetData.getStationInformation(transferResult);
ArrayList<StationInformation> parseStationInformation = new ArrayList<>();

public static void main(String[] args) throws JSONException, IOException {
DailyDustResult dailyDustResult = new DailyDustResult();
dailyDustResult.dailyAirConditionParser();
JSONObject nearestStation = stations.getJSONObject(0);
String stationName = nearestStation.getString("stationName");
String address = nearestStation.getString("addr");
String length = nearestStation.getString("tm");
StationInformation stationInformation = new StationInformation(stationName,address,length);
parseStationInformation.add(stationInformation);

return parseStationInformation;
}

}
10 changes: 10 additions & 0 deletions BE/src/main/java/com/codesquad/dust7/DustController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public ResponseEntity<ApiResponseMessage> responseAirConditionResult() throws JS
}
}

@GetMapping("/location")
public ResponseEntity<ApiResponseMessage> responseStationInfo(@RequestParam String coordinateWGS84) throws JSONException{
DailyDustResult dailyDustResult = new DailyDustResult();
try{
return new ResponseEntity<>(new ApiResponseMessage(HttpStatus.OK, dailyDustResult.stationInformations(coordinateWGS84),200),HttpStatus.OK);
} catch (IOException e) {
return new ResponseEntity<>(new ApiResponseMessage(HttpStatus.BAD_REQUEST, "에러가 발생하였습니다!!", 404), HttpStatus.BAD_REQUEST);
}
}

}

0 comments on commit cfb6714

Please sign in to comment.