Skip to content

Commit

Permalink
Weather-service Deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
seheonnn authored Jun 27, 2024
2 parents 77e1cad + b3db115 commit 9836cd5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class BatchScheduler {

@Scheduled(cron = "0 0 2,5,8,11,14,17,20,23 * * *") // 3시간마다
public void runDailyWeatherJob() {
log.info("[ Scheduler ] DailyWeather Api");
try {
JobParameters jobParameters = new JobParametersBuilder()
.addLong("executedTime", System.currentTimeMillis())
Expand All @@ -37,6 +38,7 @@ public void runDailyWeatherJob() {

@Scheduled(cron = "0 0 * * * *") // 1시간마다
public void runExpectedWeatherJob() {
log.info("[ Scheduler ] ExpectedWeather Api");
try {
JobParameters jobParameters = new JobParametersBuilder()
.addLong("executedTime", System.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.waither.weatherservice.response.ApiResponse;
import com.waither.weatherservice.service.WeatherService;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

Expand All @@ -20,12 +21,22 @@ public class WeatherController {

private final WeatherService weatherService;

@Operation(summary = "모든 날씨 정보 가져오기 - 프론트, noti-service 사용",
description = "{"
+ "\"latitude\": 37.41,"
+ "\"longitude\": 126.73"
+ "}")
@GetMapping("/main")
public ApiResponse<MainWeatherResponse> getMainWeather(@ModelAttribute @Valid GetWeatherRequest getWeatherRequest) {
return ApiResponse.onSuccess(
weatherService.getMainWeather(getWeatherRequest.latitude(), getWeatherRequest.longitude()));
}

@Operation(summary = "위도, 경도 -> 지역 변환",
description = "{"
+ "\"latitude\": 37.41,"
+ "\"longitude\": 126.73"
+ "}")
@GetMapping("/region")
public ApiResponse<String> convertGpsToRegionName(@ModelAttribute @Valid GetWeatherRequest getWeatherRequest) {
return ApiResponse.onSuccess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record GetWeatherRequest(
@NotBlank(message = "[ERROR] 위도 입력은 필수 입니다.")
@NotNull(message = "[ERROR] 위도 입력은 필수 입니다.")
@DecimalMin(value = "33.0", message = "[ERROR] 위도는 33.0도에서 43.0도 사이여야 합니다.")
@DecimalMax(value = "43.0", message = "[ERROR] 위도는 33.0도에서 43.0도 사이여야 합니다.")
double latitude,
@NotBlank(message = "[ERROR] 경도 입력은 필수 입니다.")
Double latitude,
@NotNull(message = "[ERROR] 경도 입력은 필수 입니다.")
@DecimalMin(value = "124.0", message = "[ERROR] 경도는 124.0도에서 132.0도 사이여야 합니다.")
@DecimalMax(value = "132.0", message = "[ERROR] 경도는 124.0도에서 132.0도 사이여야 합니다.")
double longitude
Double longitude
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.waither.weatherservice.entity.WeatherAdvisory;
import com.waither.weatherservice.exception.WeatherExceptionHandler;
import com.waither.weatherservice.gps.GpsTransfer;
import com.waither.weatherservice.gps.LatXLngY;
import com.waither.weatherservice.kafka.KafkaMessage;
import com.waither.weatherservice.kafka.Producer;
import com.waither.weatherservice.openapi.ForeCastOpenApiResponse;
Expand Down Expand Up @@ -160,11 +159,13 @@ public void convertLocation(double latitude, double longitude) throws URISyntaxE
}

public MainWeatherResponse getMainWeather(double latitude, double longitude) {
LatXLngY latXLngY = GpsTransfer.convertGpsToGrid(latitude, longitude);

LocalDateTime now = LocalDateTime.now();

List<Region> region = regionRepository.findRegionByLatAndLong(latitude, longitude);

if (region.isEmpty())
throw new WeatherExceptionHandler(WeatherErrorCode.WEATHER_MAIN_ERROR);

String key = region.get(0).getRegionName() + "_" + convertLocalDateTimeToString(now);

// 테스트 키 : "서울특별시_20240508_1500"
Expand Down

0 comments on commit 9836cd5

Please sign in to comment.