Skip to content

Commit

Permalink
Merge branch 'main' into feature/new_schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
hisemsem authored Oct 11, 2023
2 parents 66d73ce + 4106917 commit 7365d63
Show file tree
Hide file tree
Showing 33 changed files with 1,339 additions and 1,045 deletions.
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 @@ -233,11 +233,8 @@ public String resolveToken(String requestAccessTokenInHeader) {
log.info("에러 발생!");
throw new IllegalArgumentException("Invalid token in Authorization header");
}
String token = requestAccessTokenInHeader.substring(7);

if (token.length() != 203)
throw new IllegalArgumentException("Invalid token in Authorization header");

String token = requestAccessTokenInHeader.substring(7);
return token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public ScheduleService scheduleService(){
}


}
}
29 changes: 0 additions & 29 deletions src/main/java/com/haemil/backend/map/controller/MapController.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/com/haemil/backend/map/dto/RespMapDto.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
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.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,59 +16,86 @@
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
@RequiredArgsConstructor
@RequestMapping("/prepare")
public class PrepareController {
private final PrepareService prepareService;
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;

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

ResponseEntity<BaseResponse> livingResponse = livingController.sendGetRequest();
List<LivingInfoDto> todayLivings = livingController.infoList;

List<String> temps = weatherController.tmnAndTmxData;
// log.info("minmax = {}", temps.get(0));

PrepareDto prepareDto = new PrepareDto(todayTemps, todayAirs, temps, todayLivings);
prepareService.filterWeatherData(todayTemps, prepareDto);
// log.info("tmp = {}", prepareDto.getTmp());

prepareService.filterAirData(todayAirs, prepareDto);

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

String resultString = prepareService.ParsingJson(prepareDtoList);
log.info("prePare_result = {}", resultString);

Object jsonResult = objectMapper.readValue(resultString, Object.class);
String prettyJsonString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonResult);

return new BaseResponse<>(prettyJsonString).convert();
} catch(BaseException e) {
return new BaseResponse<>(e.getStatus()).convert();
} catch (JsonProcessingException e) {
return new BaseResponse<>(ResponseStatus.CANNOT_CONVERT_JSON).convert();
}
private final PrepareService prepareService;
private final WeatherController weatherController;
private final LivingController livingController;
private final AirController airController;

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

List<WeatherInfoDto> todayTemps = weatherController.currentTimeData;
Map<String, String> temps = weatherController.transformedData; // 최고 최저 온도

ResponseEntity<BaseResponse> airResponse = airController.sendGetRequest(request);
List<AirInfoDto> todayAirs = airController.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);

return prepareDto;
}

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

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

List<PrePareInfoDto> resultString = prepareService.ParsingJson(prepareDtoList);

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);

List<PrepareWeatherDto> resultString = prepareService.ParsingWeather(prepareDtoList);

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);

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

List<PrepareNeedInfoDto> resultString = prepareService.ParsingNeed(prepareDtoList);

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 mask; // 미세먼지 농도 값에 따른 마스크 착용 -> 옵션 ) 자율, 권고, 필수
private String clothes; // 기온별 옷차림 -> 옵션 ) ex. "민소매, 반팔, 반바지, 원피스"
private boolean umbrella; // 강수량에 따른 우선 여부
private String feel_like; // 체감 온도
private int percent; // 외출 적합도 퍼센트
private String result; // 외출 적합도 문장 -> 옵션 ) ex. "외출하기 좋은 날이네요"ㅇ
private String pm10value; // 가장 최근꺼로 오늘꺼 미세먼지 수치
private String clothes; // 기온별 옷차림 -> 옵션 ) ex. "민소매, 반팔, 반바지, 원피스"
private String feel_like; // 체감 온도
private String uv; // 자외선
private String result; // 외출 적합도 문장 -> 옵션 ) ex. "외출하기 좋은 날이네요"
private int percent; // 외출 적합도 퍼센트
}
Loading

0 comments on commit 7365d63

Please sign in to comment.