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

Feature/exchange #73

Merged
merged 3 commits into from
May 30, 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 @@ -30,6 +30,7 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -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 {

Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public BaseResponse<List<DuesListResponseDto>> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public class LoginUserAuditorAware implements AuditorAware<Long> {
@Override
public Optional<Long> getCurrentAuditor() {
Member member = (Member)httpSession.getAttribute("loginUserIdx");
return Optional.ofNullable(member != null? member.getMemberIdx():null);
return Optional.ofNullable(1L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

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;
private BigDecimal duesAmount;
private List<RequestMemberInfo> memberInfos;

@Getter
@ToString
public static class RequestMemberInfo {
private Long memberIdx;
private String fcmToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public Tasklet tasklet() {
List<ExchangeDto> 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());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class ExchangeRate {
@Column(nullable = false, length = 10)
private String curCd;

@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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,9 +25,11 @@ public class ExchangeDto {
private String kftc_deal_bas_r; // 서울외국환중개장부가격


public ExchangeRateResponseDto toDto() {
return ExchangeRateResponseDto.builder()
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();
}
Expand All @@ -35,6 +38,7 @@ public ExchangeRate saveExchangeRate() {
return ExchangeRate.builder()
.rate(BigDecimalConverter.convertStringToBigDecimal(deal_bas_r))
.curCd(cur_unit)
.curName(cur_nm)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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<ExchangeRateResponse> exchangeRates;

}

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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 cur_icon;
private String deal_bas_r; // 매매 기준율
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -35,19 +38,20 @@ public class ExchangeService {
private final ExchangeUtils exchangeUtils;
private FirebaseFCMService firebaseFCMService;

public List<ExchangeRateResponseDto> getExchangeRate(){
public ExchangeRateInfoResponseDto getExchangeRate(){

List<ExchangeDto> exchangeDtoList = exchangeUtils.getExchangeDataAsDtoList();
List<ExchangeRateResponseDto> exchangeRateResponseDtos = new ArrayList<>();
List<ExchangeRateResponse> 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 exchangeRateResponseDtos;
return ExchangeRateInfoResponseDto.builder().exchangeRateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))).exchangeRates(exchangeRateResponseDtos).build();
}

@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) {
Expand All @@ -56,7 +60,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());
}
}

Expand Down
Loading