From f2c70de7a78166256697d5c66abf52055e387f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Thu, 30 May 2024 15:12:14 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20exchange=5Frate=20cur=5Fname=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/firebase/FirebaseFCMService.java | 43 ++++++++++++++++--- .../dues/controller/DuesController.java | 1 + .../domain/entity/LoginUserAuditorAware.java | 2 +- .../dues/dto/request/DuesAlarmRequestDto.java | 3 ++ .../exchangeRate/batch/ExchangeBatch.java | 4 +- .../domain/entity/ExchangeRate.java | 3 ++ .../exchangeRate/dto/ExchangeDto.java | 2 + .../dto/request/ExchangeRateResponseDto.java | 1 + .../exchangeRate/service/ExchangeService.java | 4 +- 9 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java index af532cd..67bb816 100644 --- a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java +++ b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseFCMService.java @@ -30,6 +30,7 @@ import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -95,12 +96,35 @@ private String makeMessage(FcmSendDto fcmSendDto) throws JsonProcessingException private void firebaseCreateOption() throws IOException { - FileInputStream refreshToken = new FileInputStream(firebaseConfigPath); - FirebaseOptions options = FirebaseOptions.builder() - .setCredentials(GoogleCredentials.fromStream(refreshToken)) - .build(); + try { + InputStream refreshToken = new ClassPathResource(firebaseConfigPath).getInputStream(); + + FirebaseApp firebaseApp = null; + List firebaseApps = FirebaseApp.getApps(); + + if(firebaseApps != null && !firebaseApps.isEmpty()){ + + for(Object app : firebaseApps){ + if (app instanceof FirebaseApp) { + FirebaseApp apps = (FirebaseApp) app; + if (apps.getName().equals(FirebaseApp.DEFAULT_APP_NAME)) { + firebaseApp = (FirebaseApp) app; + } + } + } + + }else{ + FirebaseOptions options = FirebaseOptions.builder() + .setCredentials(GoogleCredentials.fromStream(refreshToken)).build(); + + FirebaseApp.initializeApp(options); + } + + + } catch (IOException e) { + throw new RuntimeException(e.getMessage()); + } - FirebaseApp.initializeApp(options); } public BaseResponse notificationAlarm(String title, String body, DuesAlarmRequestDto duesAlarmRequestDto) throws IOException, FirebaseMessagingException { @@ -118,7 +142,14 @@ public BaseResponse notificationAlarm(String title, String body, DuesAlarmReques .addAllTokens(tokenList) .build(); - BatchResponse response = FirebaseMessaging.getInstance().sendEachForMulticast(message); + try { + BatchResponse response = FirebaseMessaging.getInstance().sendEachForMulticast(message); + System.out.println("FCMsendsuccess-"+response); + } catch (FirebaseMessagingException e) { + System.out.println("FCMsend-"+e.getMessage()); + } + + //BatchResponse response = FirebaseMessaging.getInstance().sendEachForMulticast(message); Team team =teamRepository.findById(duesAlarmRequestDto.getTeamIdx()).orElseThrow(()->new ApiException(ExceptionEnum.TEAM_NOT_FOUND)); diff --git a/src/main/java/com/hanaro/triptogether/dues/controller/DuesController.java b/src/main/java/com/hanaro/triptogether/dues/controller/DuesController.java index c68e665..5372319 100644 --- a/src/main/java/com/hanaro/triptogether/dues/controller/DuesController.java +++ b/src/main/java/com/hanaro/triptogether/dues/controller/DuesController.java @@ -39,6 +39,7 @@ public BaseResponse> getDuesList(@RequestParam("teamId @PostMapping("/request") public BaseResponse requestDuesToMember(@RequestBody DuesAlarmRequestDto duesAlarmRequestDto) throws IOException, FirebaseMessagingException { + System.out.println("asdfasdf"+duesAlarmRequestDto.toString()+duesAlarmRequestDto.getMemberInfos().toString()); return firebaseFCMService.notificationAlarm("회비 요청 알림",duesAlarmRequestDto.getDuesAmount().toString(),duesAlarmRequestDto); } diff --git a/src/main/java/com/hanaro/triptogether/dues/domain/entity/LoginUserAuditorAware.java b/src/main/java/com/hanaro/triptogether/dues/domain/entity/LoginUserAuditorAware.java index 74bdf90..d955c92 100644 --- a/src/main/java/com/hanaro/triptogether/dues/domain/entity/LoginUserAuditorAware.java +++ b/src/main/java/com/hanaro/triptogether/dues/domain/entity/LoginUserAuditorAware.java @@ -19,6 +19,6 @@ public class LoginUserAuditorAware implements AuditorAware { @Override public Optional getCurrentAuditor() { Member member = (Member)httpSession.getAttribute("loginUserIdx"); - return Optional.ofNullable(member != null? member.getMemberIdx():null); + return Optional.ofNullable(1L); } } diff --git a/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesAlarmRequestDto.java b/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesAlarmRequestDto.java index 953946d..80ec0ab 100644 --- a/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesAlarmRequestDto.java +++ b/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesAlarmRequestDto.java @@ -2,12 +2,14 @@ import lombok.Getter; import lombok.Setter; +import lombok.ToString; import java.math.BigDecimal; import java.util.List; @Getter @Setter +@ToString public class DuesAlarmRequestDto { private Long teamIdx; @@ -15,6 +17,7 @@ public class DuesAlarmRequestDto { private List memberInfos; @Getter + @ToString public static class RequestMemberInfo { private Long memberIdx; private String fcmToken; diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/batch/ExchangeBatch.java b/src/main/java/com/hanaro/triptogether/exchangeRate/batch/ExchangeBatch.java index 867a65f..38cabb5 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/batch/ExchangeBatch.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/batch/ExchangeBatch.java @@ -49,9 +49,7 @@ public Tasklet tasklet() { List exchangeDtoList = exchangeUtils.getExchangeDataAsDtoList(); for(ExchangeDto exchangeDto: exchangeDtoList){ - System.out.println("통화코드 :" + exchangeDto.getCur_unit()); - System.out.println("환율 : "+ exchangeDto.getDeal_bas_r()); - exchangeService.saveExchangeRate(exchangeDto.getCur_unit(),exchangeDto.getDeal_bas_r()); + exchangeService.saveExchangeRate(exchangeDto.getCur_unit(),exchangeDto.getDeal_bas_r(),exchangeDto.getCur_nm()); } 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 34b4c30..1eea0fa 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 @@ -24,6 +24,9 @@ public class ExchangeRate { @Column(nullable = false, length = 10) private String curCd; + @Column(nullable = false, length = 10) + private String curName; + @Column(nullable = false, precision = 20, scale = 2) private BigDecimal rate; diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java index f171655..99f61c8 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java @@ -27,6 +27,7 @@ public class ExchangeDto { public ExchangeRateResponseDto toDto() { return ExchangeRateResponseDto.builder() .cur_unit(cur_unit) + .cur_name(cur_nm) .deal_bas_r(deal_bas_r) .build(); } @@ -35,6 +36,7 @@ public ExchangeRate saveExchangeRate() { return ExchangeRate.builder() .rate(BigDecimalConverter.convertStringToBigDecimal(deal_bas_r)) .curCd(cur_unit) + .curName(cur_nm) .build(); } } diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponseDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponseDto.java index 29ee73e..c2ee275 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponseDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponseDto.java @@ -9,5 +9,6 @@ @AllArgsConstructor public class ExchangeRateResponseDto { private String cur_unit; // 통화코드 + private String cur_name; //국가 이름 private String 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 fcb34e9..3c81ac0 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -47,7 +47,7 @@ public List getExchangeRate(){ } @Transactional - public void saveExchangeRate(String curCode, String curRate) { + public void saveExchangeRate(String curCode, String curRate,String curName) { ExchangeRate existingExchangeRate = exchangeRateRepository.findExchangeRateByCurCd(curCode); if (existingExchangeRate != null) { @@ -56,7 +56,7 @@ public void saveExchangeRate(String curCode, String curRate) { }else { - exchangeRateRepository.save(ExchangeRate.builder().rate(BigDecimalConverter.convertStringToBigDecimal(curRate)).curCd(curCode).build()); + exchangeRateRepository.save(ExchangeRate.builder().rate(BigDecimalConverter.convertStringToBigDecimal(curRate)).curCd(curCode).curName(curName).build()); } } From 53ea38f57961ab52dfad1dfec4cc24a4e593758f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Thu, 30 May 2024 15:36:21 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20exchange=5Frate=20response=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exchangeRate/dto/ExchangeDto.java | 7 ++++--- .../request/ExchangeRateInfoResponseDto.java | 19 +++++++++++++++++++ ...onseDto.java => ExchangeRateResponse.java} | 10 +++++----- .../exchangeRate/service/ExchangeService.java | 11 +++++++---- 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateInfoResponseDto.java rename src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/{ExchangeRateResponseDto.java => ExchangeRateResponse.java} (68%) diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java index 99f61c8..5e9a6bd 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java @@ -2,7 +2,8 @@ import com.hanaro.triptogether.common.BigDecimalConverter; import com.hanaro.triptogether.exchangeRate.domain.entity.ExchangeRate; -import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateResponseDto; +import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateInfoResponseDto; +import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateResponse; import lombok.*; @Getter @@ -24,8 +25,8 @@ public class ExchangeDto { private String kftc_deal_bas_r; // 서울외국환중개장부가격 - public ExchangeRateResponseDto toDto() { - return ExchangeRateResponseDto.builder() + public ExchangeRateResponse toDto() { + return ExchangeRateResponse.builder() .cur_unit(cur_unit) .cur_name(cur_nm) .deal_bas_r(deal_bas_r) diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateInfoResponseDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateInfoResponseDto.java new file mode 100644 index 0000000..63864a8 --- /dev/null +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateInfoResponseDto.java @@ -0,0 +1,19 @@ +package com.hanaro.triptogether.exchangeRate.dto.request; + +import lombok.*; + +import java.time.LocalDateTime; +import java.util.List; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ExchangeRateInfoResponseDto { + + private String exchangeRateTime; + private List exchangeRates; + +} + diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponseDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponse.java similarity index 68% rename from src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponseDto.java rename to src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponse.java index c2ee275..57df5d8 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponseDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/request/ExchangeRateResponse.java @@ -1,13 +1,13 @@ package com.hanaro.triptogether.exchangeRate.dto.request; -import lombok.*; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +@Builder @Getter @Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class ExchangeRateResponseDto { +public class ExchangeRateResponse { private String cur_unit; // 통화코드 private String cur_name; //국가 이름 private String 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 3c81ac0..7815efa 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -9,7 +9,8 @@ import com.hanaro.triptogether.exchangeRate.domain.repository.ExchangeRateRepository; import com.hanaro.triptogether.exchangeRate.dto.ExchangeDto; import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateAlarmRequestDto; -import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateResponseDto; +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.exception.EntityNotFoundException; import com.hanaro.triptogether.exchangeRate.utils.ExchangeUtils; @@ -21,6 +22,8 @@ import java.io.IOException; import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -35,15 +38,15 @@ public class ExchangeService { private final ExchangeUtils exchangeUtils; private FirebaseFCMService firebaseFCMService; - public List getExchangeRate(){ + public ExchangeRateInfoResponseDto getExchangeRate(){ List exchangeDtoList = exchangeUtils.getExchangeDataAsDtoList(); - List exchangeRateResponseDtos = new ArrayList<>(); + List exchangeRateResponseDtos = new ArrayList<>(); for(ExchangeDto exchangeDto: exchangeDtoList){ exchangeRateResponseDtos.add(exchangeDto.toDto()); } - return exchangeRateResponseDtos; + return ExchangeRateInfoResponseDto.builder().exchangeRateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))).exchangeRates(exchangeRateResponseDtos).build(); } @Transactional From 1acce693bbb88d9fda3ba7877d9899e317049b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Thu, 30 May 2024 16:11:25 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20exchange=5Frate=20icon=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../triptogether/exchangeRate/domain/entity/ExchangeRate.java | 3 +++ .../com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java | 3 ++- .../exchangeRate/dto/request/ExchangeRateResponse.java | 1 + .../triptogether/exchangeRate/service/ExchangeService.java | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) 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 1eea0fa..8e7ac6d 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 @@ -27,6 +27,9 @@ public class ExchangeRate { @Column(nullable = false, length = 10) private String curName; + @Column(nullable = false, length = 10) + private String curIcon; + @Column(nullable = false, precision = 20, scale = 2) private BigDecimal rate; diff --git a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java index 5e9a6bd..111662b 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/dto/ExchangeDto.java @@ -25,10 +25,11 @@ public class ExchangeDto { private String kftc_deal_bas_r; // 서울외국환중개장부가격 - public ExchangeRateResponse toDto() { + 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(); } 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 57df5d8..ece2cb5 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 @@ -10,5 +10,6 @@ public class ExchangeRateResponse { private String cur_unit; // 통화코드 private String cur_name; //국가 이름 + private String cur_icon; private String 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 7815efa..471cbb5 100644 --- a/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java +++ b/src/main/java/com/hanaro/triptogether/exchangeRate/service/ExchangeService.java @@ -43,7 +43,8 @@ public ExchangeRateInfoResponseDto getExchangeRate(){ List exchangeDtoList = exchangeUtils.getExchangeDataAsDtoList(); List exchangeRateResponseDtos = new ArrayList<>(); for(ExchangeDto exchangeDto: exchangeDtoList){ - exchangeRateResponseDtos.add(exchangeDto.toDto()); + ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCd(exchangeDto.getCur_unit()); + exchangeRateResponseDtos.add(exchangeDto.toDto(exchangeRate.getCurIcon())); } return ExchangeRateInfoResponseDto.builder().exchangeRateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))).exchangeRates(exchangeRateResponseDtos).build();