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

[refactor] 도시 상세 환율 정보 조회 API 변경 및 로직 리팩토링 수정 #120

Merged
merged 1 commit into from
Jan 25, 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 @@ -31,15 +31,15 @@ public ResponseEntity<ResponseDTO<CityInfoResponseDto>> getCityInfo(
);
}

@GetMapping("/exchange-rates")
@GetMapping("/{cityId}/exchange-rates")
public ResponseEntity<ResponseDTO<ExchangeRateResponseDto>> getExchangeRate(
@RequestParam(name = "curUnit") String curUnit
@PathVariable("cityId") Long cityId
) {

return ResponseEntity
.status(HttpStatus.OK)
.body(
ResponseDTO.okWithData(cityInfoReadService.getExchangeRate(curUnit))
ResponseDTO.okWithData(cityInfoReadService.getExchangeRateByCityId(cityId))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RequiredArgsConstructor
Expand All @@ -39,9 +38,12 @@ public CityInfoResponseDto getCityInfo(Long id) {
}

@Transactional(readOnly = true)
public ExchangeRateResponseDto getExchangeRate(String curUnit) {
CurrencyUnit currencyUnit = validateAndConvertToCurrencyUnit(curUnit);
public ExchangeRateResponseDto getExchangeRateByCityId(Long cityId) {

City city = cityRepository.findById(cityId)
.orElseThrow(CityNotFoundException::new);

CurrencyUnit currencyUnit = city.getCurrency();
String exchangeRate = (String) redisTemplate.opsForValue()
.get("exchange-rate:" + currencyUnit);

Expand Down Expand Up @@ -105,11 +107,4 @@ private String convertToTempF(String tempC) {
.setScale(2, RoundingMode.HALF_UP)
.toString();
}

private CurrencyUnit validateAndConvertToCurrencyUnit(String curUnit) {
return Arrays.stream(CurrencyUnit.values())
.filter(currencyUnit -> currencyUnit.name().equals(curUnit.toUpperCase()))
.findFirst()
.orElseThrow();
}
}
Loading