Skip to content

Commit

Permalink
refactor: refactor portfolio stock domain
Browse files Browse the repository at this point in the history
  • Loading branch information
songyi00 committed Apr 6, 2024
1 parent b429ff9 commit 63158d9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package nexters.payout.domain.portfolio.domain;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.*;
import lombok.Getter;
import nexters.payout.domain.BaseEntity;

Expand All @@ -17,23 +14,18 @@
@Getter
public class Portfolio extends BaseEntity {

@ElementCollection
@CollectionTable(name = "portfolio_stock", joinColumns = @JoinColumn(name = "portfolio_id"))
private List<PortfolioStock> stocks = new ArrayList<>();
@Embedded
private PortfolioStocks portfolioStocks;

private Instant expireAt;

public Portfolio() {
super(null);
}

public Portfolio(final UUID id, final Instant expireAt) {
super(id);
this.expireAt = expireAt;
}

public Portfolio(final Instant expireAt, List<PortfolioStock> stocks) {
super(null);
this.stocks = stocks;
this.portfolioStocks = new PortfolioStocks(stocks);
this.expireAt = expireAt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,8 @@ public class PortfolioStock {
private UUID stockId;
private Integer shares;


public PortfolioStock(final UUID id, final UUID stockId, final Integer shares) {
public PortfolioStock(final UUID stockId, final Integer shares) {
this.stockId = stockId;
this.shares = shares;
}

private PortfolioStock(final UUID stockId, final Integer shares) {
this.stockId = stockId;
this.shares = shares;
}

public PortfolioStock create(final UUID portfolioId, final UUID stockId, final Integer shares) {
return new PortfolioStock(portfolioId, stockId, shares);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nexters.payout.domain.portfolio.domain;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Embeddable;
import jakarta.persistence.JoinColumn;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@NoArgsConstructor
@Embeddable
public class PortfolioStocks {

@ElementCollection
@CollectionTable(name = "portfolio_stock", joinColumns = @JoinColumn(name = "portfolio_id"))
private List<PortfolioStock> portfolioStocks = new ArrayList<>();

public PortfolioStocks(List<PortfolioStock> stocks) {
if (stocks.isEmpty()) {
throw new IllegalArgumentException("portfolioStocks must not be empty");
}
portfolioStocks = stocks;
}

public List<PortfolioStock> getPortfolioStocks() {
return Collections.unmodifiableList(portfolioStocks);
}
}

0 comments on commit 63158d9

Please sign in to comment.