diff --git a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java index 296971c..108cd0c 100644 --- a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java +++ b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java @@ -21,16 +21,11 @@ public class FirebaseConfig { @Bean public FirebaseApp firebaseApp() throws IOException { - System.out.println("fcm"); InputStream resource = new ClassPathResource("triptogether-e7bac-firebase-adminsdk-peiki-127517aa66.json").getInputStream(); -// JsonReader jsonReader = new JsonReader(new InputStreamReader(resource)); -// jsonReader.setLenient(true); byte[] jsonBytes = resource.readAllBytes(); - System.out.println("fcm"); String jsonString = new String(jsonBytes, StandardCharsets.UTF_8); - System.out.println("fcm"+jsonString); // Gson을 사용하여 JSON 문자열을 JsonObject로 파싱 Gson gson = new Gson(); diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/controller/ExchangeRateAlarmController.java b/src/main/java/com/hanaro/triptogether/exchangeRate/controller/ExchangeRateAlarmController.java index 2ded7eb..abec303 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/controller/ExchangeRateAlarmController.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/controller/ExchangeRateAlarmController.java @@ -28,5 +28,11 @@ public BaseResponse> getExchangeRateAlarmList return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage(),exchangeService.getExchangeRateAlarmList(memberIdx)); } + @DeleteMapping("/exchange-rate/{memberIdx}") + public BaseResponse deleteAlarm(@PathVariable("memberIdx") Long memberIdx){ + exchangeService.deleteAlarm(memberIdx); + return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage()); + } + } 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 ecd8d60..ae5f15d 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 @@ -21,8 +21,8 @@ public class ExchangeRate { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long curIdx; - @Column(nullable = false, length = 10) - private String curCd; + @Column(name = "curCode",nullable = false, length = 10) + private String curCode; @Column(nullable = false, length = 10) private String curName; @@ -31,7 +31,7 @@ public class ExchangeRate { private String curIcon; @Column(nullable = false, precision = 20, scale = 2) - private BigDecimal rate; + private BigDecimal curRate; @Column(nullable = false) private LocalDateTime createdAt; @@ -60,7 +60,7 @@ protected void onCreate() { } public void updateExchangeRate(BigDecimal curRate){ - this.rate = curRate; + this.curRate = curRate; } diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRateAlarm.java b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRateAlarm.java index 1351f64..ff63014 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRateAlarm.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/entity/ExchangeRateAlarm.java @@ -33,12 +33,6 @@ public class ExchangeRateAlarm extends BaseEntity { @JoinColumn(name = "member_idx", nullable = false) private Member member; - @Column(name = "cur_code", nullable = false) - private String curCode; - - @Column(name = "cur_name", nullable = false) - private String curName; - @Column(name = "cur_rate", nullable = false) private BigDecimal curRate; @@ -54,12 +48,14 @@ public void setNotified(boolean notify){ this.notified = notify; } - public ExchangeRateAlarmResponseDto toDto(ExchangeRateAlarm exchangeRateAlarm) { + public ExchangeRateAlarmResponseDto toDto(ExchangeRateAlarm exchangeRateAlarm,ExchangeRate exchangeRate) { return ExchangeRateAlarmResponseDto.builder() - .curCode(exchangeRateAlarm.getCurCode()) + .idx(exchangeRateAlarm.alarmIdx) + .curIcon(exchangeRate.getCurIcon()) + .curCode(exchangeRate.getCurCode()) .curType(exchangeRateAlarm.getRateType()) .curRate(exchangeRateAlarm.getCurRate()) - .curName(exchangeRateAlarm.getCurName()) + .curName(exchangeRate.getCurName()) .build(); } diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateAlarmRepository.java b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateAlarmRepository.java index e197b33..eb58236 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateAlarmRepository.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateAlarmRepository.java @@ -7,5 +7,7 @@ public interface ExchangeRateAlarmRepository extends JpaRepository { - List findExchangeRateAlarmByMember_MemberIdx(Long memberIdx); + List findExchangeRatesAlarmByMember_MemberIdx(Long memberIdx); + + ExchangeRateAlarm findExchangeRateAlarmByMember_MemberIdx(Long memberIdx); } diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateRepository.java b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateRepository.java index 25bba9f..7ee9c2a 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateRepository.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/domain/repository/ExchangeRateRepository.java @@ -5,5 +5,5 @@ public interface ExchangeRateRepository extends JpaRepository { - ExchangeRate findExchangeRateByCurCd(String curCd); + ExchangeRate findExchangeRateByCurCode(String curCode); } diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateAlarmRequestDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateAlarmRequestDto.java index 7326628..22eecab 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateAlarmRequestDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateAlarmRequestDto.java @@ -27,8 +27,6 @@ public ExchangeRateAlarm toEntity(Member member, ExchangeRate exchangeRate) { .fcmToken(fcmToken) .exchangeRate(exchangeRate) .rateType(rateAlarmType) - .curCode(curCode) - .curName(exchangeRate.getCurName()) .curRate(BigDecimalConverter.convertStringToBigDecimal(curRate)).build(); } 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 3a129cb..6d757e4 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 @@ -36,8 +36,8 @@ public ExchangeRateResponse toDto(String cur_icon) { public ExchangeRate saveExchangeRate() { return ExchangeRate.builder() - .rate(BigDecimalConverter.convertStringToBigDecimal(deal_bas_r)) - .curCd(cur_unit) + .curRate(BigDecimalConverter.convertStringToBigDecimal(deal_bas_r)) + .curCode(cur_unit) .curName(cur_nm) .build(); } diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeRateAlarmResponseDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeRateAlarmResponseDto.java index febd66c..9425696 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeRateAlarmResponseDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/response/ExchangeRateAlarmResponseDto.java @@ -11,8 +11,11 @@ @Setter @Builder public class ExchangeRateAlarmResponseDto { + + private Long idx; private String curCode; private String curName; + private String curIcon; private BigDecimal curRate; private ExchangeRateAlarmType curType; 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 ecdccc1..88c6197 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -44,7 +44,7 @@ public ExchangeRateInfoResponseDto getExchangeRate(){ List exchangeDtoList = exchangeUtils.getExchangeDataAsDtoList(); List exchangeRateResponseDtos = new ArrayList<>(); for(ExchangeDto exchangeDto: exchangeDtoList){ - ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCd(exchangeDto.getCur_unit()); + ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCode(exchangeDto.getCur_unit()); exchangeRateResponseDtos.add(exchangeDto.toDto(exchangeRate.getCurIcon())); } @@ -52,12 +52,16 @@ public ExchangeRateInfoResponseDto getExchangeRate(){ } public List getExchangeRateAlarmList(Long memberIdx) { - return exchangeRateAlarmRepository.findExchangeRateAlarmByMember_MemberIdx(memberIdx).stream().map(exchangeRateAlarm -> exchangeRateAlarm.toDto(exchangeRateAlarm)).toList(); + + return exchangeRateAlarmRepository.findExchangeRatesAlarmByMember_MemberIdx(memberIdx).stream().map(entity -> { + ExchangeRate exchangeRate = exchangeRateRepository.findById(entity.getExchangeRate().getCurIdx()).orElseThrow(EntityNotFoundException::new); + return entity.toDto(entity,exchangeRate); + }).toList(); } @Transactional public void saveExchangeRate(String curCode, String curRate,String curName) { - ExchangeRate existingExchangeRate = exchangeRateRepository.findExchangeRateByCurCd(curCode); + ExchangeRate existingExchangeRate = exchangeRateRepository.findExchangeRateByCurCode(curCode); if (existingExchangeRate != null) { existingExchangeRate.updateExchangeRate(BigDecimalConverter.convertStringToBigDecimal(curRate)); @@ -65,14 +69,14 @@ public void saveExchangeRate(String curCode, String curRate,String curName) { }else { - exchangeRateRepository.save(ExchangeRate.builder().rate(BigDecimalConverter.convertStringToBigDecimal(curRate)).curCd(curCode).curName(curName).build()); + exchangeRateRepository.save(ExchangeRate.builder().curRate(BigDecimalConverter.convertStringToBigDecimal(curRate)).curCode(curCode).curName(curName).build()); } } @Transactional public void setExchangeRateAlarm(ExchangeRateAlarmRequestDto requestDto){ Member member = memberRepository.findById(requestDto.getMemberIdx()).orElseThrow(EntityNotFoundException::new); - ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCd(requestDto.getCurCode()); + ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCode(requestDto.getCurCode()); exchangeRateAlarmRepository.save(requestDto.toEntity(member,exchangeRate)); } @@ -85,9 +89,9 @@ public void checkNotifyAlarms() throws IOException { if(alarm.getNotified()) { continue; } - ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCd(alarm.getCurCode()); - BigDecimal currRate = exchangeRate.getRate(); - if(alarm.getCurCode().equals(exchangeRate.getCurCd())){ + ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCode(alarm.getExchangeRate().getCurCode()); + BigDecimal currRate = exchangeRate.getCurRate(); + if(alarm.getExchangeRate().getCurCode().equals(exchangeRate.getCurCode())){ boolean notify = false; if (alarm.getRateType() == ExchangeRateAlarmType.OVER && currRate.compareTo(alarm.getCurRate()) >= 0) { notify = true; @@ -116,4 +120,11 @@ public void resetNotifiedFlags() { } } + + @Transactional + public void deleteAlarm(Long memberIdx) { + ExchangeRateAlarm exchangeRateAlarm = exchangeRateAlarmRepository.findExchangeRateAlarmByMember_MemberIdx(memberIdx); + exchangeRateAlarmRepository.delete(exchangeRateAlarm); + } + }