diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRate.java b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRate.java index ae5f15d..0e6a882 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRate.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRate.java @@ -1,5 +1,6 @@ package com.hanaro.triptogether.exchangeRate.domain.entity; +import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateResponse; import com.hanaro.triptogether.member.domain.Member; import jakarta.persistence.*; import lombok.AllArgsConstructor; @@ -52,6 +53,15 @@ public class ExchangeRate { @JoinColumn(name = "deleted_by", insertable=false, updatable=false) private Member deletedBy; + public ExchangeRateResponse toDto(String cur_icon) { + return ExchangeRateResponse.builder() + .cur_code(curCode) + .cur_name(curName) + .cur_icon(cur_icon) + .cur_rate(String.valueOf(curRate)) + .build(); + } + @PrePersist protected void onCreate() { LocalDateTime now = LocalDateTime.now(); diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponse.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponse.java index ece2cb5..fae18bf 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponse.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponse.java @@ -8,8 +8,8 @@ @Getter @Setter public class ExchangeRateResponse { - private String cur_unit; // 통화코드 - private String cur_name; //국가 이름 + private String cur_code; + private String cur_name; private String cur_icon; - private String deal_bas_r; // 매매 기준율 + private String cur_rate; } diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeDto.java index 6d757e4..b8e80a4 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeDto.java @@ -25,15 +25,6 @@ public class ExchangeDto { private String kftc_deal_bas_r; // 서울외국환중개장부가격 - public ExchangeRateResponse toDto(String cur_icon) { - return ExchangeRateResponse.builder() - .cur_unit(cur_unit) - .cur_name(cur_nm) - .cur_icon(cur_icon) - .deal_bas_r(deal_bas_r) - .build(); - } - public ExchangeRate saveExchangeRate() { return ExchangeRate.builder() .curRate(BigDecimalConverter.convertStringToBigDecimal(deal_bas_r)) diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java index 88c6197..1ff5533 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -7,14 +7,12 @@ import com.hanaro.triptogether.exchangeRate.domain.entity.ExchangeRateAlarm; import com.hanaro.triptogether.exchangeRate.domain.repository.ExchangeRateAlarmRepository; import com.hanaro.triptogether.exchangeRate.domain.repository.ExchangeRateRepository; -import com.hanaro.triptogether.exchangeRate.dto.response.ExchangeDto; import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateAlarmRequestDto; import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateInfoResponseDto; import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateResponse; import com.hanaro.triptogether.exchangeRate.dto.request.FcmSendDto; import com.hanaro.triptogether.exchangeRate.dto.response.ExchangeRateAlarmResponseDto; import com.hanaro.triptogether.exchangeRate.exception.EntityNotFoundException; -import com.hanaro.triptogether.exchangeRate.utils.ExchangeUtils; import com.hanaro.triptogether.member.domain.Member; import com.hanaro.triptogether.member.domain.MemberRepository; import lombok.RequiredArgsConstructor; @@ -36,19 +34,18 @@ public class ExchangeService { private final MemberRepository memberRepository; private final ExchangeRateRepository exchangeRateRepository; - private final ExchangeUtils exchangeUtils; private final FirebaseFCMService firebaseFCMService; public ExchangeRateInfoResponseDto getExchangeRate(){ - List exchangeDtoList = exchangeUtils.getExchangeDataAsDtoList(); - List exchangeRateResponseDtos = new ArrayList<>(); - for(ExchangeDto exchangeDto: exchangeDtoList){ - ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCode(exchangeDto.getCur_unit()); - exchangeRateResponseDtos.add(exchangeDto.toDto(exchangeRate.getCurIcon())); + List exchangeRateDtoList = exchangeRateRepository.findAll(); + List exchangeRateResponses = new ArrayList<>(); + for(ExchangeRate exchangeDto: exchangeRateDtoList){ + ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCode(exchangeDto.getCurCode()); + exchangeRateResponses.add(exchangeDto.toDto(exchangeRate.getCurIcon())); } - return ExchangeRateInfoResponseDto.builder().exchangeRateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))).exchangeRates(exchangeRateResponseDtos).build(); + return ExchangeRateInfoResponseDto.builder().exchangeRateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))).exchangeRates(exchangeRateResponses).build(); } public List getExchangeRateAlarmList(Long memberIdx) {