Skip to content

Commit

Permalink
[refactor] CityInfoReadService 리팩토링: getCityEntity 메서드 삭제
Browse files Browse the repository at this point in the history
related to: #140
  • Loading branch information
jo0oy committed Jan 31, 2024
1 parent 991882b commit 119b287
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public class CityInfoReadService {
private static final int WEATHER_MONTH_GAP = 3;

@Transactional(readOnly = true)
public CityInfoResponseDto getCityInfo(Long id) {
public CityInfoResponseDto getCityInfo(Long cityId) {
return CityInfoResponseDto.fromEntity(
getCityEntity(id)
cityRepository.findById(cityId)
.orElseThrow(CityNotFoundException::new)
);
}

Expand All @@ -56,8 +57,9 @@ public ExchangeRateResponseDto getExchangeRateByCityId(Long cityId) {
}

@Transactional(readOnly = true)
public List<WeatherResponseDto> getWeatherInfo(Long id) {
City city = getCityEntity(id);
public List<WeatherResponseDto> getWeatherInfo(Long cityId) {
City city = cityRepository.findById(cityId)
.orElseThrow(CityNotFoundException::new);

// 현재 달 포함 향후 3개월
int curMonth = LocalDate.now().getMonthValue();
Expand All @@ -75,11 +77,6 @@ public List<WeatherResponseDto> getWeatherInfo(Long id) {
).toList();
}

private City getCityEntity(Long id) {
return cityRepository.findById(id)
.orElseThrow(CityNotFoundException::new);
}

private List<Weather> sortWeatherInfos(List<Weather> weathers) {
int lastIdx = weathers.size() - 1;

Expand Down

0 comments on commit 119b287

Please sign in to comment.