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/dues paid #154

Merged
merged 2 commits into from
Jun 10, 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 @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ public BaseResponse<List<ExchangeRateAlarmResponseDto>> 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());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -60,7 +60,7 @@ protected void onCreate() {
}

public void updateExchangeRate(BigDecimal curRate){
this.rate = curRate;
this.curRate = curRate;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@

public interface ExchangeRateAlarmRepository extends JpaRepository<ExchangeRateAlarm,Long> {

List<ExchangeRateAlarm> findExchangeRateAlarmByMember_MemberIdx(Long memberIdx);
List<ExchangeRateAlarm> findExchangeRatesAlarmByMember_MemberIdx(Long memberIdx);

ExchangeRateAlarm findExchangeRateAlarmByMember_MemberIdx(Long memberIdx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface ExchangeRateRepository extends JpaRepository<ExchangeRate,Long> {

ExchangeRate findExchangeRateByCurCd(String curCd);
ExchangeRate findExchangeRateByCurCode(String curCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,39 @@ public ExchangeRateInfoResponseDto getExchangeRate(){
List<ExchangeDto> exchangeDtoList = exchangeUtils.getExchangeDataAsDtoList();
List<ExchangeRateResponse> 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()));

}
return ExchangeRateInfoResponseDto.builder().exchangeRateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))).exchangeRates(exchangeRateResponseDtos).build();
}

public List<ExchangeRateAlarmResponseDto> 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));
exchangeRateRepository.save(existingExchangeRate);

}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));
}

Expand All @@ -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;
Expand Down Expand Up @@ -116,4 +120,11 @@ public void resetNotifiedFlags() {
}
}


@Transactional
public void deleteAlarm(Long memberIdx) {
ExchangeRateAlarm exchangeRateAlarm = exchangeRateAlarmRepository.findExchangeRateAlarmByMember_MemberIdx(memberIdx);
exchangeRateAlarmRepository.delete(exchangeRateAlarm);
}

}
Loading