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

[ADD] latitude, longitude #26

Merged
merged 29 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4fb6875
[FEAT] add schedule api
hisemsem Jul 16, 2023
5bdc1cf
[FEAT] add schedule api
hisemsem Aug 9, 2023
3911116
[FEAT] add schedule api
hisemsem Aug 17, 2023
83e612a
Merge branch 'feature/schedule' into main
hisemsem Aug 17, 2023
19d12ca
Merge branch 'main' into feature/schedule
hisemsem Aug 17, 2023
225b136
Merge branch 'main' into feature/schedule
devyubin Aug 17, 2023
f79f992
[CHORE] add schedule api
hisemsem Aug 26, 2023
3463403
Merge branch 'main' into feature/schedule
devyubin Aug 26, 2023
9317387
[CHORE] add schedule api
hisemsem Aug 27, 2023
91c8f78
Merge remote-tracking branch 'origin/feature/schedule' into feature/s…
hisemsem Aug 27, 2023
2f3f8a0
[CHORE] schedule api
hisemsem Aug 30, 2023
114d98c
Merge pull request #6 from hanium-haemil/feature/schedule
devyubin Aug 30, 2023
0ecb4a4
Merge remote-tracking branch 'origin/main' into feature/weather
hyun-jung-joo Aug 30, 2023
c403e12
[CHORE] modify weather api
hyun-jung-joo Aug 30, 2023
1ab1346
Merge pull request #23 from hanium-haemil/feature/weather
hyun-jung-joo Aug 30, 2023
59f2800
Merge remote-tracking branch 'origin/main' into feature/weather
hyun-jung-joo Aug 30, 2023
a0911b0
[CHORE] weather/prepare code refactor
hyun-jung-joo Sep 4, 2023
418a119
Merge pull request #24 from hanium-haemil/feature/weather
hyun-jung-joo Sep 4, 2023
40489e6
[FEAT] add schedule api
hisemsem Jul 16, 2023
5876b93
[FEAT] add schedule api
hisemsem Aug 17, 2023
0220dec
[CHORE] add schedule api
hisemsem Aug 26, 2023
a906b54
[CHORE] add schedule api
hisemsem Aug 27, 2023
6031874
[CHORE] schedule api
hisemsem Aug 30, 2023
c7a41d7
[CHORE] modify weather api
hyun-jung-joo Aug 30, 2023
6c39957
[CHORE] weather/prepare code refactor
hyun-jung-joo Sep 4, 2023
3a2691b
Merge remote-tracking branch 'origin/main' into main
devyubin Sep 4, 2023
92e6e99
Merge remote-tracking branch 'origin/main' into feature/weather
hyun-jung-joo Sep 4, 2023
6bf4dc7
Merge remote-tracking branch 'origin/main' into feature/weather
hyun-jung-joo Sep 15, 2023
455fd2a
[ADD] latitude, longitude
hyun-jung-joo Sep 15, 2023
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
28 changes: 14 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ services:
networks:
- db_network

/*# spring-boot:
# container_name: server-haemil
# build:
# context: .
# dockerfile: Dockerfile-dev
# restart: always
# environment:
# - TZ=Asia/Seoul
# ports:
# - "8080:8080"
# depends_on:
# - redis
# networks:
# - db_network*/
spring-boot:
container_name: server-haemil
build:
context: .
dockerfile: Dockerfile-dev
restart: always
environment:
- TZ=Asia/Seoul
ports:
- "8080:8080"
depends_on:
- redis
networks:
- db_network

networks:
db_network:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
Expand All @@ -23,12 +24,12 @@ public class AlertController {
private final GetApiDto getApiDto;

@PostMapping("/send")
public ResponseEntity<BaseResponse> sendGetRequest(@RequestBody ReqCoordDto reqCoordDto) {
public ResponseEntity<BaseResponse> sendGetRequest(HttpServletRequest request) {

try {
String jsonString = alertService.getAlertInfo(getApiDto);
alertService.isJson(jsonString);
List<AlertDto> alertApiList = alertService.ParsingJson(jsonString, reqCoordDto);
List<AlertDto> alertApiList = alertService.ParsingJson(jsonString, request);
return new BaseResponse<>(alertApiList).convert();
} catch (BaseException e){
// 실패시 custom한 status로 code 헤더 설정, body로 메세지 반환
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -77,9 +78,9 @@ public String getAlertInfo(GetApiDto reqGetApiDto) throws BaseException {
// 임시
private final LocationService locationService;

public List<AlertDto> ParsingJson(String responseBody, ReqCoordDto reqCoordDto) throws BaseException {
public List<AlertDto> ParsingJson(String responseBody, HttpServletRequest request) throws BaseException {
try {
String fullLocationJsonString = locationService.getLocationInfo(reqCoordDto);
String fullLocationJsonString = locationService.getLocationInfo(request);
String userLocation = ParsingLocation(fullLocationJsonString);

List<AlertDto> alertApiList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public ScheduleService scheduleService(){
}


}
}
4 changes: 2 additions & 2 deletions src/main/java/com/haemil/backend/map/service/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public String getMapUrl(String reqLocation) throws BaseException {
String address = reqLocation;
String addr = URLEncoder.encode(address, "UTF-8");

log.debug("address = {}", address);
// log.debug("address = {}", address);

// Geocoding 개요에 나와있는 API URL 입력.
String apiURL = "https://dapi.kakao.com/v2/local/search/keyword.json?page=1&size=1&sort=accuracy&query="+addr;

URL url = new URL(apiURL);
log.debug("url = {}", url);
// log.debug("url = {}", url);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.haemil.backend.global.config.BaseException;
import com.haemil.backend.global.config.BaseResponse;
import com.haemil.backend.global.config.ResponseStatus;
import com.haemil.backend.prepare.dto.PrepareDto;
import com.haemil.backend.prepare.dto.*;
import com.haemil.backend.prepare.service.PrepareService;
import com.haemil.backend.weather.controller.AirController;
import com.haemil.backend.weather.controller.LivingController;
Expand All @@ -19,9 +19,11 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
Expand All @@ -32,46 +34,77 @@ public class PrepareController {
private final WeatherController weatherController;
private final LivingController livingController;
private final AirController airController;
private final ObjectMapper objectMapper; // ObjectMapper 주입

@GetMapping("/send")
public ResponseEntity<BaseResponse> sendGetRequest() {
try {
// Call /weather/send to get weather data
ResponseEntity<BaseResponse> weatherResponse = weatherController.sendGetRequest();
List<WeatherInfoDto> todayTemps = weatherController.currentTimeData;
private PrepareDto fetchDataAndProcess(HttpServletRequest request) throws BaseException {
String latitude = request.getParameter("latitude");
String longitude = request.getParameter("longitude");

// Call /air/send to get air data
ResponseEntity<BaseResponse> airResponse = airController.sendGetRequest();
List<AirInfoDto> todayAirs = airController.infoList;
ResponseEntity<BaseResponse> weatherResponse = weatherController.sendGetRequest(request);

ResponseEntity<BaseResponse> livingResponse = livingController.sendGetRequest();
List<LivingInfoDto> todayLivings = livingController.infoList;
List<WeatherInfoDto> todayTemps = weatherController.currentTimeData;
Map<String, String> temps = weatherController.transformedData; // 최고 최저 온도

List<String> temps = weatherController.tmnAndTmxData;
// log.info("minmax = {}", temps.get(0));
ResponseEntity<BaseResponse> airResponse = airController.sendGetRequest(request);
List<AirInfoDto> todayAirs = airController.infoList;

PrepareDto prepareDto = new PrepareDto(todayTemps, todayAirs, temps, todayLivings);
prepareService.filterWeatherData(todayTemps, prepareDto);
// log.info("tmp = {}", prepareDto.getTmp());
ResponseEntity<BaseResponse> livingResponse = livingController.sendGetRequest(request);
List<LivingInfoDto> todayLivings = livingController.infoList;

prepareService.filterAirData(todayAirs, prepareDto);
PrepareDto prepareDto = new PrepareDto(todayTemps, todayAirs, temps, todayLivings);
prepareService.filterWeatherData(todayTemps, prepareDto);
prepareService.filterAirData(todayAirs, prepareDto);

return prepareDto;
}

@GetMapping("/send")
public ResponseEntity<BaseResponse> sendGetRequest(HttpServletRequest request) {
try {
PrepareDto prepareDto = fetchDataAndProcess(request);

List<PrepareDto> prepareDtoList = new ArrayList<>();
prepareDtoList.add(prepareDto);

String resultString = prepareService.ParsingJson(prepareDtoList);
log.info("prePare_result = {}", resultString);
List<PrePareInfoDto> resultString = prepareService.ParsingJson(prepareDtoList);
// log.info("prePare_result = {}", resultString); // 외출 적합도 결과 log

return new BaseResponse<>(resultString).convert();
} catch(BaseException e) {
return new BaseResponse<>(e.getStatus()).convert();
}
}

@GetMapping("/weather")
public ResponseEntity<BaseResponse> sendWeatherInfo(HttpServletRequest request) {
try {
PrepareDto prepareDto = fetchDataAndProcess(request);

List<PrepareDto> prepareDtoList = new ArrayList<>();
prepareDtoList.add(prepareDto);

Object jsonResult = objectMapper.readValue(resultString, Object.class);
String prettyJsonString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonResult);
List<PrepareWeatherDto> resultString = prepareService.ParsingWeather(prepareDtoList);
// log.info("prePare_weather_result = {}", resultString); // 외출 - 날씨 관련 정보

return new BaseResponse<>(prettyJsonString).convert();
return new BaseResponse<>(resultString).convert();
} catch(BaseException e) {
return new BaseResponse<>(e.getStatus()).convert();
} catch (JsonProcessingException e) {
return new BaseResponse<>(ResponseStatus.CANNOT_CONVERT_JSON).convert();
}
}
}

@GetMapping("/need")
public ResponseEntity<BaseResponse> sendNeedInfo(HttpServletRequest request) {
try {
PrepareDto prepareDto = fetchDataAndProcess(request);

List<PrepareDto> prepareDtoList = new ArrayList<>();
prepareDtoList.add(prepareDto);

List<PrepareNeedInfoDto> resultString = prepareService.ParsingNeed(prepareDtoList);
// log.info("prePare_need_result = {}", resultString); // 외출 물품 정보

return new BaseResponse<>(resultString).convert();
} catch(BaseException e) {
return new BaseResponse<>(e.getStatus()).convert();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

@Data
public class PrePareInfoDto {
private String mask; // 미세먼지 농도 값에 따른 마스크 착용 -> 옵션 ) 자율, 권고, 필수
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String clothes; // 기온별 옷차림 -> 옵션 ) ex. "민소매, 반팔, 반바지, 원피스"
private boolean umbrella; // 강수량에 따른 우선 여부
private String feel_like; // 체감 온도
private String uv; // 자외선
private String result; // 외출 적합도 문장 -> 옵션 ) ex. "외출하기 좋은 날이네요"
private int percent; // 외출 적합도 퍼센트
private String result; // 외출 적합도 문장 -> 옵션 ) ex. "외출하기 좋은 날이네요"ㅇ
}
14 changes: 9 additions & 5 deletions src/main/java/com/haemil/backend/prepare/dto/PrepareDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Data
@Component
Expand All @@ -26,25 +27,28 @@ public class PrepareDto {
private String pcp; // 1시간 강수량
private String reh; // 습도
private String sky; // 하늘 상태
private String wsd; // 풍속(m/s)

// 대기질
private String pm10grade; // 가장 최근꺼로 오늘꺼 미세먼지 등급
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String pm25grade; // 가장 최근꺼로 오늘꺼 초미세먼지 등급
private String pm25value; // 가장 최근꺼로 오늘꺼 미세먼지 수치

// living
private String feelLike; // 체감 온도
private String uv; // 자외선

// 기본 생성자
public PrepareDto() {
}

// 필요한 데이터를 주입받는 생성자
public PrepareDto(List<WeatherInfoDto> todayTemps, List<AirInfoDto> todayAirs, List<String> temps, List<LivingInfoDto> livings) {
public PrepareDto(List<WeatherInfoDto> todayTemps, List<AirInfoDto> todayAirs, Map<String, String> temps, List<LivingInfoDto> livings) {
this.todayTemps = todayTemps;
this.todayAirs = todayAirs;
this.maxTemp = temps.get(1);
this.minTemp = temps.get(0);
String maxTemp = temps.get("max");
String minTemp = temps.get("min");
this.maxTemp = maxTemp;
this.minTemp = minTemp;

if (!livings.isEmpty()) {
this.feelLike = livings.get(0).getFeels_like();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.haemil.backend.prepare.dto;
import lombok.Data;
import org.springframework.stereotype.Component;

@Data
@Component
public class PrepareNeedInfoDto {
private String mask; // 미세먼지 농도 값에 따른 마스크 착용 -> 옵션 ) 자율, 권고, 필수
private String umbrella; // 강수량에 따른 우선 여부
private String clothes; // 기온별 옷차림 -> 옵션 ) ex. "민소매, 반팔, 반바지, 원피스"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.haemil.backend.prepare.dto;

import lombok.Data;
import org.springframework.stereotype.Component;

@Data
@Component
public class PrepareWeatherDto {
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String pm25value; // 가장 최근꺼로 오늘꺼 미세먼지 수치

private String pop; // 강수 확률
private String pcp; // 1시간 강수량

private String wsd; // 풍속(m/s)
private String uv; // 자외선
}
Loading
Loading