Skip to content

Commit

Permalink
Merge pull request #30 from hanium-haemil/feature/prepare
Browse files Browse the repository at this point in the history
[REFACTOR] code refactoring - weather, prepare
  • Loading branch information
hyun-jung-joo authored Oct 6, 2023
2 parents 8ca26e6 + 79b7fce commit 4106917
Show file tree
Hide file tree
Showing 24 changed files with 1,202 additions and 1,184 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.haemil.backend.prepare.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
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.*;
import com.haemil.backend.prepare.service.PrepareService;
import com.haemil.backend.weather.controller.AirController;
Expand All @@ -30,81 +27,75 @@
@RequiredArgsConstructor
@RequestMapping("/prepare")
public class PrepareController {
private final PrepareService prepareService;
private final WeatherController weatherController;
private final LivingController livingController;
private final AirController airController;
private final PrepareService prepareService;
private final WeatherController weatherController;
private final LivingController livingController;
private final AirController airController;

private PrepareDto fetchDataAndProcess(HttpServletRequest request) throws BaseException {
String latitude = request.getParameter("latitude");
String longitude = request.getParameter("longitude");
private PrepareDto fetchDataAndProcess(HttpServletRequest request) throws BaseException {
ResponseEntity<BaseResponse> weatherResponse = weatherController.sendGetRequest(request);

ResponseEntity<BaseResponse> weatherResponse = weatherController.sendGetRequest(request);
List<WeatherInfoDto> todayTemps = weatherController.currentTimeData;
Map<String, String> temps = weatherController.transformedData; // 최고 최저 온도

List<WeatherInfoDto> todayTemps = weatherController.currentTimeData;
Map<String, String> temps = weatherController.transformedData; // 최고 최저 온도
ResponseEntity<BaseResponse> airResponse = airController.sendGetRequest(request);
List<AirInfoDto> todayAirs = airController.infoList;

ResponseEntity<BaseResponse> airResponse = airController.sendGetRequest(request);
List<AirInfoDto> todayAirs = airController.infoList;
ResponseEntity<BaseResponse> livingResponse = livingController.sendGetRequest(request);
List<LivingInfoDto> todayLivings = livingController.infoList;

ResponseEntity<BaseResponse> livingResponse = livingController.sendGetRequest(request);
List<LivingInfoDto> todayLivings = livingController.infoList;
PrepareDto prepareDto = new PrepareDto(todayTemps, todayAirs, temps, todayLivings);
prepareService.filterWeatherData(todayTemps, prepareDto);
prepareService.filterAirData(todayAirs, prepareDto);

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

return prepareDto;
}

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

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

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

return new BaseResponse<>(resultString).convert();
} catch(BaseException e) {
return new BaseResponse<>(e.getStatus()).convert();
}
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);
@GetMapping("/weather")
public ResponseEntity<BaseResponse> sendWeatherInfo(HttpServletRequest request) {
try {
PrepareDto prepareDto = fetchDataAndProcess(request);

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

List<PrepareWeatherDto> resultString = prepareService.ParsingWeather(prepareDtoList);
// log.info("prePare_weather_result = {}", resultString); // 외출 - 날씨 관련 정보
List<PrepareWeatherDto> resultString = prepareService.ParsingWeather(prepareDtoList);

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

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

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

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

return new BaseResponse<>(resultString).convert();
} catch(BaseException e) {
return new BaseResponse<>(e.getStatus()).convert();
}
return new BaseResponse<>(resultString).convert();
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus()).convert();
}
}
}
13 changes: 7 additions & 6 deletions src/main/java/com/haemil/backend/prepare/dto/PrePareInfoDto.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.haemil.backend.prepare.dto;

import lombok.Data;

@Data
public class PrePareInfoDto {
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String clothes; // 기온별 옷차림 -> 옵션 ) ex. "민소매, 반팔, 반바지, 원피스"
private String feel_like; // 체감 온도
private String uv; // 자외선
private String result; // 외출 적합도 문장 -> 옵션 ) ex. "외출하기 좋은 날이네요"
private int percent; // 외출 적합도 퍼센트
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String clothes; // 기온별 옷차림 -> 옵션 ) ex. "민소매, 반팔, 반바지, 원피스"
private String feel_like; // 체감 온도
private String uv; // 자외선
private String result; // 외출 적합도 문장 -> 옵션 ) ex. "외출하기 좋은 날이네요"
private int percent; // 외출 적합도 퍼센트
}
84 changes: 43 additions & 41 deletions src/main/java/com/haemil/backend/prepare/dto/PrepareDto.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.haemil.backend.prepare.dto;

import com.haemil.backend.weather.controller.WeatherController;
import com.haemil.backend.weather.controller.AirController;
import com.haemil.backend.weather.dto.AirInfoDto;
Expand All @@ -13,46 +14,47 @@
@Data
@Component
public class PrepareDto {
private WeatherController weatherController;
private AirController airController;
private List<WeatherInfoDto> todayTemps;
private List<AirInfoDto> todayAirs;
private String maxTemp; // 오늘 최고 온도
private String minTemp; // 오늘 최저 온도

// 현재 실시간(시간별) weather 정보
private String tmp; // 1시간 온도
private String pop; // 강수 확률
private String pty; // 강수 형태
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, Map<String, String> temps, List<LivingInfoDto> livings) {
this.todayTemps = todayTemps;
this.todayAirs = todayAirs;
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();
this.uv = livings.get(0).getUvi();
}
private WeatherController weatherController;
private AirController airController;
private List<WeatherInfoDto> todayTemps;
private List<AirInfoDto> todayAirs;
private String maxTemp; // 오늘 최고 온도
private String minTemp; // 오늘 최저 온도

// 현재 실시간(시간별) weather 정보
private String tmp; // 1시간 온도
private String pop; // 강수 확률
private String pty; // 강수 형태
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(
List<WeatherInfoDto> todayTemps,
List<AirInfoDto> todayAirs,
Map<String, String> temps,
List<LivingInfoDto> livings) {
this.todayTemps = todayTemps;
this.todayAirs = todayAirs;
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();
this.uv = livings.get(0).getUvi();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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. "민소매, 반팔, 반바지, 원피스"
private String mask; // 미세먼지 농도 값에 따른 마스크 착용 -> 옵션 ) 자율, 권고, 필수
private String umbrella; // 강수량에 따른 우선 여부
private String clothes; // 기온별 옷차림 -> 옵션 ) ex. "민소매, 반팔, 반바지, 원피스"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
@Data
@Component
public class PrepareWeatherDto {
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String pm25value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String pm25value; // 가장 최근꺼로 오늘꺼 미세먼지 수치

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

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

0 comments on commit 4106917

Please sign in to comment.