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

πŸ›fix: main api 및 지역 λ³€ν™˜ api μˆ˜μ • #117

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading