Skip to content

Commit

Permalink
Merge pull request #120 from Hanaro-trip-together-bank/feature/dues-req
Browse files Browse the repository at this point in the history
refactor: 환율 알림 db 수정 및 api 변경
  • Loading branch information
ny2060 authored Jun 5, 2024
2 parents 94a62fe + e7752e3 commit 25fdc9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hanaro.triptogether.exchangeRate.domain.entity;
import com.hanaro.triptogether.dues.domain.entity.BaseEntity;
import com.hanaro.triptogether.enumeration.ExchangeRateAlarmType;
import com.hanaro.triptogether.member.domain.Member;
import com.hanaro.triptogether.team.domain.Team;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand All @@ -17,19 +18,20 @@
@NoArgsConstructor
@AllArgsConstructor
public class ExchangeRateAlarm extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "alarm_idx")
@Column(name = "exchange_rate_alarm_idx")
private Long alarmIdx;

@ManyToOne
@JoinColumn(name = "team_idx", nullable = false)
private Team team;

@ManyToOne
@JoinColumn(name = "cur_idx", nullable = false)
private ExchangeRate exchangeRate;

@ManyToOne
@JoinColumn(name = "member_idx", nullable = false)
private Member member;

@Column(name = "cur_Code", nullable = false)
private String curCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.hanaro.triptogether.enumeration.ExchangeRateAlarmType;
import com.hanaro.triptogether.exchangeRate.domain.entity.ExchangeRate;
import com.hanaro.triptogether.exchangeRate.domain.entity.ExchangeRateAlarm;
import com.hanaro.triptogether.member.domain.Member;
import com.hanaro.triptogether.team.domain.Team;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -16,15 +17,15 @@
@ToString
public class ExchangeRateAlarmRequestDto {

private Long teamIdx;
private Long memberIdx;
private String curCode;
private String curRate;
private ExchangeRateAlarmType rateAlarmType;
private String fcmToken;

public ExchangeRateAlarm toEntity(Team team, ExchangeRate exchangeRate) {
public ExchangeRateAlarm toEntity(Member member, ExchangeRate exchangeRate) {
return ExchangeRateAlarm.builder()
.team(team)
.member(member)
.fcmToken(fcmToken)
.exchangeRate(exchangeRate)
.rateType(rateAlarmType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.hanaro.triptogether.exchangeRate.dto.request.FcmSendDto;
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 com.hanaro.triptogether.team.domain.Team;
import com.hanaro.triptogether.team.domain.TeamRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -33,6 +35,7 @@ public class ExchangeService {

private final ExchangeRateAlarmRepository exchangeRateAlarmRepository;
private final TeamRepository teamRepository;
private final MemberRepository memberRepository;
private final ExchangeRateRepository exchangeRateRepository;

private final ExchangeUtils exchangeUtils;
Expand Down Expand Up @@ -66,9 +69,9 @@ public void saveExchangeRate(String curCode, String curRate,String curName) {

@Transactional
public void setExchangeRateAlarm(ExchangeRateAlarmRequestDto requestDto){
Team team = teamRepository.findById(requestDto.getTeamIdx()).orElseThrow(EntityNotFoundException::new);
Member member = memberRepository.findById(requestDto.getMemberIdx()).orElseThrow(EntityNotFoundException::new);
ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurCd(requestDto.getCurCode());
exchangeRateAlarmRepository.save(requestDto.toEntity(team,exchangeRate));
exchangeRateAlarmRepository.save(requestDto.toEntity(member,exchangeRate));
}

@Transactional
Expand Down Expand Up @@ -100,7 +103,6 @@ public void checkNotifyAlarms() throws IOException {

}

System.out.println("ssssaaaa"+alarms.size());
}

@Transactional
Expand Down

0 comments on commit 25fdc9d

Please sign in to comment.