Skip to content

Commit

Permalink
Merge pull request #136 from Hanaro-trip-together-bank/feature/dues_paid
Browse files Browse the repository at this point in the history
feat: 환율 알림 리스트 조회 api 구현
  • Loading branch information
ny2060 authored Jun 6, 2024
2 parents 6bb506d + 7a4b850 commit 914978d
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hanaro.triptogether.exchangeRate.batch;

import com.hanaro.triptogether.exchangeRate.dto.ExchangeDto;
import com.hanaro.triptogether.exchangeRate.dto.response.ExchangeDto;
import com.hanaro.triptogether.exchangeRate.service.ExchangeService;
import com.hanaro.triptogether.exchangeRate.utils.ExchangeUtils;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import com.hanaro.triptogether.common.response.BaseResponse;
import com.hanaro.triptogether.common.response.ResponseStatus;
import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateAlarmRequestDto;
import com.hanaro.triptogether.exchangeRate.dto.response.ExchangeRateAlarmResponseDto;
import com.hanaro.triptogether.exchangeRate.service.ExchangeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -22,5 +23,10 @@ public BaseResponse setExchangeRateAlarm(@RequestBody ExchangeRateAlarmRequestDt
return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage());
}

@GetMapping("/exchange-rate/{memberIdx}")
public BaseResponse<List<ExchangeRateAlarmResponseDto>> getExchangeRateAlarmList(@PathVariable("memberIdx") Long memberIdx){
return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage(),exchangeService.getExchangeRateAlarmList(memberIdx));
}


}
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.exchangeRate.dto.response.ExchangeRateAlarmResponseDto;
import com.hanaro.triptogether.member.domain.Member;
import com.hanaro.triptogether.team.domain.Team;
import jakarta.persistence.*;
Expand Down Expand Up @@ -32,9 +33,12 @@ public class ExchangeRateAlarm extends BaseEntity {
@JoinColumn(name = "member_idx", nullable = false)
private Member member;

@Column(name = "cur_Code", nullable = false)
@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 @@ -43,12 +47,21 @@ public class ExchangeRateAlarm extends BaseEntity {
private Boolean notified;

@Enumerated(EnumType.STRING)
@Column(name = "rate_type", nullable = false, columnDefinition = "ENUM('over', 'less')")
@Column(name = "rate_type", nullable = false, columnDefinition = "ENUM('OVER', 'LESS')")
private ExchangeRateAlarmType rateType;

public void setNotified(boolean notify){
this.notified = notify;
}

public ExchangeRateAlarmResponseDto toDto(ExchangeRateAlarm exchangeRateAlarm) {
return ExchangeRateAlarmResponseDto.builder()
.curCode(exchangeRateAlarm.getCurCode())
.curType(exchangeRateAlarm.getRateType())
.curRate(exchangeRateAlarm.getCurRate())
.curName(exchangeRateAlarm.getCurName())
.build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
import com.hanaro.triptogether.exchangeRate.domain.entity.ExchangeRateAlarm;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ExchangeRateAlarmRepository extends JpaRepository<ExchangeRateAlarm,Long> {

List<ExchangeRateAlarm> findExchangeRateAlarmByMember_MemberIdx(Long memberIdx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
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;
import lombok.ToString;

import java.math.BigDecimal;

@Getter
@Setter
Expand All @@ -30,6 +28,7 @@ public ExchangeRateAlarm toEntity(Member member, ExchangeRate exchangeRate) {
.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
@@ -1,4 +1,4 @@
package com.hanaro.triptogether.exchangeRate.dto;
package com.hanaro.triptogether.exchangeRate.dto.response;

import com.hanaro.triptogether.common.BigDecimalConverter;
import com.hanaro.triptogether.exchangeRate.domain.entity.ExchangeRate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hanaro.triptogether.exchangeRate.dto.response;

import com.hanaro.triptogether.enumeration.ExchangeRateAlarmType;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

@Getter
@Setter
@Builder
public class ExchangeRateAlarmResponseDto {
private String curCode;
private String curName;
private BigDecimal curRate;
private ExchangeRateAlarmType curType;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import com.hanaro.triptogether.exchangeRate.domain.entity.ExchangeRateAlarm;
import com.hanaro.triptogether.exchangeRate.domain.repository.ExchangeRateAlarmRepository;
import com.hanaro.triptogether.exchangeRate.domain.repository.ExchangeRateRepository;
import com.hanaro.triptogether.exchangeRate.dto.ExchangeDto;
import com.hanaro.triptogether.exchangeRate.dto.response.ExchangeDto;
import com.hanaro.triptogether.exchangeRate.dto.request.ExchangeRateAlarmRequestDto;
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.dto.response.ExchangeRateAlarmResponseDto;
import com.hanaro.triptogether.exchangeRate.exception.EntityNotFoundException;
import com.hanaro.triptogether.exchangeRate.utils.ExchangeUtils;
import com.hanaro.triptogether.member.domain.Member;
Expand Down Expand Up @@ -50,6 +51,10 @@ public ExchangeRateInfoResponseDto getExchangeRate(){
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();
}

@Transactional
public void saveExchangeRate(String curCode, String curRate,String curName) {
ExchangeRate existingExchangeRate = exchangeRateRepository.findExchangeRateByCurCd(curCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hanaro.triptogether.exchangeRate.dto.ExchangeDto;
import com.hanaro.triptogether.exchangeRate.dto.response.ExchangeDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down

0 comments on commit 914978d

Please sign in to comment.