-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feature: Weather-Service로 부터 해당 시각의 체감 온도 받아오는 메서드 작성
- Loading branch information
Showing
12 changed files
with
60 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
user-service/src/main/java/com/waither/userservice/entity/UserMedian.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
...rvice/src/main/java/com/waither/userservice/global/jwt/filter/JwtAuthorizationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...serservice/global/util/CalculateUtil.java → ...ither/userservice/util/CalculateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...er/userservice/global/util/RedisUtil.java → ...m/waither/userservice/util/RedisUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
user-service/src/main/java/com/waither/userservice/util/RestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.waither.userservice.util; | ||
|
||
import com.waither.userservice.global.exception.CustomException; | ||
import com.waither.userservice.global.response.ApiResponse; | ||
import com.waither.userservice.global.response.ErrorCode; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
@Component | ||
public class RestClient { | ||
public static final String WEATHER_SERVICE_URL = "http://localhost:8081"; | ||
|
||
private final WebClient webClient; | ||
|
||
public RestClient(WebClient.Builder webClientBuilder) { | ||
this.webClient = webClientBuilder.baseUrl(WEATHER_SERVICE_URL).build(); | ||
} | ||
|
||
public Double getTemperature(double latitude, double longitude, LocalDateTime time) { | ||
ApiResponse<String> response = webClient.get() | ||
.uri(uriBuilder -> uriBuilder | ||
.path("/weather/temperature") | ||
.queryParam("latitude", latitude) | ||
.queryParam("longitude", longitude) | ||
.queryParam("baseTime", time.format(DateTimeFormatter.ISO_DATE_TIME)) | ||
.build()) | ||
.retrieve() | ||
.onStatus(HttpStatusCode::isError, clientResponse -> | ||
Mono.error(new CustomException(ErrorCode.INTERNAL_SERVER_ERROR_500))) | ||
.bodyToMono(new ParameterizedTypeReference<ApiResponse<String>>() {}) | ||
.block(); | ||
|
||
if (response != null && "COMMON200".equals(response.getCode())) { | ||
return Double.parseDouble(response.getResult()); | ||
} else { | ||
throw new CustomException(ErrorCode.INTERNAL_SERVER_ERROR_500); | ||
} | ||
} | ||
} |