-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add portfolio, portfolio stock entity #89
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3ed0794
fix: fix test date time issue
chominho96 70eaeab
feat: add portfolio, portfolio stock entity
chominho96 a5d0b8c
feat: add portfolio, portfolio stock repository
chominho96 eb618a0
refactor: refactor package structure
chominho96 3cf8852
test: add test fixture
chominho96 ac42b69
setting: add db configuration
chominho96 0d6929d
fix: add @Entity annotation
chominho96 e6fa53a
fix: fix portfolio stock to element collection
chominho96 27edc1a
fix: remove portfolio id from PoltfolioStock
chominho96 1051982
setting: fix db configuration
chominho96 2abb0a6
refactor: delete create method from portfolio entity
chominho96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
domain/src/main/java/nexters/payout/domain/portfolio/domain/Portfolio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package nexters.payout.domain.portfolio.domain; | ||
|
||
import jakarta.persistence.CollectionTable; | ||
import jakarta.persistence.ElementCollection; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.JoinColumn; | ||
import lombok.Getter; | ||
import nexters.payout.domain.BaseEntity; | ||
|
||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
|
||
@Entity | ||
@Getter | ||
public class Portfolio extends BaseEntity { | ||
|
||
@ElementCollection | ||
@CollectionTable(name = "portfolio_stock", joinColumns = @JoinColumn(name = "portfolio_id")) | ||
private List<PortfolioStock> stocks = new ArrayList<>(); | ||
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.expireAt = expireAt; | ||
} | ||
|
||
public boolean isExpired() { | ||
return expireAt.isAfter(Instant.now()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
domain/src/main/java/nexters/payout/domain/portfolio/domain/PortfolioStock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package nexters.payout.domain.portfolio.domain; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.UUID; | ||
|
||
@Embeddable | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PortfolioStock { | ||
|
||
private UUID stockId; | ||
private Integer shares; | ||
|
||
|
||
public PortfolioStock(final UUID id, 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); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../src/main/java/nexters/payout/domain/portfolio/domain/repository/PortfolioRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package nexters.payout.domain.portfolio.domain.repository; | ||
|
||
import nexters.payout.domain.portfolio.domain.Portfolio; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface PortfolioRepository extends JpaRepository<Portfolio, UUID> { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
domain/src/main/resources/db/migration/V5__add_portfolio.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
create table portfolio | ||
( | ||
id binary (16) not null | ||
primary key, | ||
expire_at datetime(6), | ||
created_at datetime(6), | ||
last_modified_at datetime(6) | ||
) engine = innodb | ||
default charset = utf8mb4; | ||
|
||
create table portfolio_stock ( | ||
portfolio_id binary(16) not null, | ||
stock_id binary(16), | ||
shares integer | ||
) engine=InnoDB | ||
default charset = utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ class StockDividendAnalysisServiceTest { | |
|
||
Dividend pastDividend = DividendFixture.createDividendWithExDividendDate( | ||
UUID.randomUUID(), | ||
LocalDate.of(now.getYear(), now.getMonth().minus(1), now.getDayOfMonth()) | ||
LocalDate.of(now.getYear(), now.getMonth().minus(1), 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅋ ㅋ ㅋ 🤯🤯 |
||
.atStartOfDay(ZoneId.systemDefault()).toInstant() | ||
); | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
domain/src/testFixtures/java/nexters/payout/domain/PortfolioFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package nexters.payout.domain; | ||
|
||
import nexters.payout.domain.portfolio.domain.Portfolio; | ||
import nexters.payout.domain.portfolio.domain.PortfolioStock; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
public class PortfolioFixture { | ||
|
||
public static Portfolio createPortfolio(Instant expireAt) { | ||
return new Portfolio(UUID.randomUUID(), expireAt); | ||
} | ||
|
||
public static PortfolioStock createPortfolioStock(UUID portfolioId, UUID stockId, Integer shares) { | ||
return new PortfolioStock(UUID.randomUUID(), stockId, shares); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성 메서드 따로 만들어주신 이유가 있을까요?? 생성자와 동일한 매개변수를 받는 것으로 보여서 생성자를 사용해도 될 것 같아서요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적으로 객체를 생성할 때 정적 팩토리 메서드를 이용하는 편인데, 다른 클래스와의 일관성을 유지하기 위해 생성했어요!! 그냥 생성자를 사용하는게 더 나을까요?! 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 정적 팩터리 메서드는 생성을 위한 로직이 복잡한 경우에 주로 사용하고 아니라면 기본 생성자를 이용하는 편이긴 합니다!!
매개변수 개수가 많지 않고 생성자를 쓰는 것과 동일한 상황같아서 기본 생성자를 쓰는 것도 좋아보여요 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 팩토리 메서드를 경우에 따라 나눠쓰시는군요!! 그 방식이 오히려 더 직관적으로 보일 수도 있을것 같아요! 해당 방향으로 수정하겠습니다!!