From ecb4fa6c6bb79b66b2bec1d63ffd9eb9083b01c7 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Sun, 16 Jun 2024 15:38:52 +0900 Subject: [PATCH] =?UTF-8?q?#33=20[refactor]=20:=20=ED=83=80=EC=9E=85=20&?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dgu/backend/domain/TradingLog.java | 5 +-- .../org/dgu/backend/domain/TradingOption.java | 36 +++++++++++++------ .../org/dgu/backend/dto/DashBoardDto.java | 2 +- .../java/org/dgu/backend/dto/TradingDto.java | 9 ++--- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/org/dgu/backend/domain/TradingLog.java b/backend/src/main/java/org/dgu/backend/domain/TradingLog.java index f5e6807..eb51d8f 100644 --- a/backend/src/main/java/org/dgu/backend/domain/TradingLog.java +++ b/backend/src/main/java/org/dgu/backend/domain/TradingLog.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import org.dgu.backend.common.BaseEntity; +import java.math.BigDecimal; import java.time.LocalDateTime; @Entity @@ -33,7 +34,7 @@ public class TradingLog extends BaseEntity { private Long capital; @Column(name = "coin", nullable = false) - private Double coin; + private BigDecimal coin; @Column(name = "coin_price", nullable = false) private Long coinPrice; @@ -42,7 +43,7 @@ public class TradingLog extends BaseEntity { private Double rate; @Builder - public TradingLog(Portfolio portfolio, String type, LocalDateTime date, Long capital, Double coin, Long coinPrice, Double rate){ + public TradingLog(Portfolio portfolio, String type, LocalDateTime date, Long capital, BigDecimal coin, Long coinPrice, Double rate){ this.portfolio = portfolio; this.type = type; this.date = date; diff --git a/backend/src/main/java/org/dgu/backend/domain/TradingOption.java b/backend/src/main/java/org/dgu/backend/domain/TradingOption.java index a6f5c28..2bb4166 100644 --- a/backend/src/main/java/org/dgu/backend/domain/TradingOption.java +++ b/backend/src/main/java/org/dgu/backend/domain/TradingOption.java @@ -28,17 +28,26 @@ public class TradingOption extends BaseEntity { @JoinColumn(name = "portfolios_id", foreignKey = @ForeignKey(name = "trading_options_fk_portfolios_id")) private Portfolio portfolio; - @Column(name = "start_capital", nullable = false) - private BigDecimal startCapital; + @Column(name = "initial_capital", nullable = false) + private Long initialCapital; + + @Column(name = "current_capital", nullable = false) + private Long currentCapital; @Column(name = "avg_price") - private BigDecimal avgPrice; + private Double avgPrice; @Column(name = "trading_unit_price", nullable = false) - private BigDecimal tradingUnitPrice; + private Long tradingUnitPrice; + + @Column(name = "coin_count", nullable = false, scale = 10) + private BigDecimal coinCount; + + @Column(name = "trading_count", nullable = false) + private int tradingCount; - @Column(name = "remained_buying_count", nullable = false) - private int remainedBuyingCount; + @Column(name = "buying_count", nullable = false) + private int buyingCount; @Column(name = "start_date", nullable = false) private LocalDateTime startDate; @@ -47,17 +56,24 @@ public class TradingOption extends BaseEntity { private LocalDateTime endDate; @Builder - public TradingOption(User user, Portfolio portfolio, BigDecimal startCapital, BigDecimal tradingUnitPrice, int remainedBuyingCount, LocalDateTime startDate, LocalDateTime endDate) { + public TradingOption(User user, Portfolio portfolio, Long initialCapital, Long currentCapital, Long tradingUnitPrice, int tradingCount, int buyingCount, LocalDateTime startDate, LocalDateTime endDate) { this.user = user; this.portfolio = portfolio; - this.startCapital = startCapital; + this.initialCapital = initialCapital; + this.currentCapital = currentCapital; this.tradingUnitPrice = tradingUnitPrice; - this.remainedBuyingCount = remainedBuyingCount; + this.coinCount = BigDecimal.ZERO; + this.tradingCount = tradingCount; + this.buyingCount = buyingCount; this.startDate = startDate; this.endDate = endDate; } - public void updateAvgPrice(BigDecimal avgPrice) { + public void updateAvgPrice(Double avgPrice) { this.avgPrice = avgPrice; } + + public void updateCoinCount(BigDecimal coinCount) { + this.coinCount = coinCount; + } } \ No newline at end of file diff --git a/backend/src/main/java/org/dgu/backend/dto/DashBoardDto.java b/backend/src/main/java/org/dgu/backend/dto/DashBoardDto.java index fe31b9f..b61536b 100644 --- a/backend/src/main/java/org/dgu/backend/dto/DashBoardDto.java +++ b/backend/src/main/java/org/dgu/backend/dto/DashBoardDto.java @@ -78,7 +78,7 @@ public static DashBoardDto.RepresentativeCoinResponse of(UpbitDto.Ticker ticker, .marketName(ticker.getMarket()) .koreanName(koreanName) .englishName(englishName) - .changePrice(BigDecimal.valueOf(ticker.getPrice())) + .changePrice(ticker.getPrice()) .changeRate(BigDecimal.valueOf(ticker.getChangeRate()).setScale(5, RoundingMode.HALF_UP)) .isIncrease(ticker.getChange().equals("RISE")) .build(); diff --git a/backend/src/main/java/org/dgu/backend/dto/TradingDto.java b/backend/src/main/java/org/dgu/backend/dto/TradingDto.java index 8658a64..6f17784 100644 --- a/backend/src/main/java/org/dgu/backend/dto/TradingDto.java +++ b/backend/src/main/java/org/dgu/backend/dto/TradingDto.java @@ -11,7 +11,6 @@ import org.dgu.backend.domain.TradingOption; import org.dgu.backend.domain.User; -import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.UUID; @@ -31,9 +30,11 @@ public TradingOption to(User user, Portfolio portfolio, PortfolioOption portfoli return TradingOption.builder() .user(user) .portfolio(portfolio) - .startCapital(BigDecimal.valueOf(fund)) - .tradingUnitPrice(BigDecimal.valueOf(fund / portfolioOption.getTradingUnit())) - .remainedBuyingCount(portfolioOption.getTradingUnit()) + .initialCapital(fund) + .currentCapital(fund) + .tradingUnitPrice(fund / portfolioOption.getTradingUnit()) + .tradingCount(portfolioOption.getTradingUnit()) + .buyingCount(0) .startDate(startDate) .endDate(endDate) .build();