Skip to content

Commit

Permalink
#33 [refactor] : 타입 & 변수명 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Jun 16, 2024
1 parent 2305f64 commit ecb4fa6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
5 changes: 3 additions & 2 deletions backend/src/main/java/org/dgu/backend/domain/TradingLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.NoArgsConstructor;
import org.dgu.backend.common.BaseEntity;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity
Expand All @@ -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;
Expand All @@ -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;
Expand Down
36 changes: 26 additions & 10 deletions backend/src/main/java/org/dgu/backend/domain/TradingOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions backend/src/main/java/org/dgu/backend/dto/TradingDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit ecb4fa6

Please sign in to comment.