-
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: implement portfolio batch service #92
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1b773dd
refactor: divide client package
songyi00 9079a31
feat: implement portfolio batch service
songyi00 dfc2d4f
test: add test code
songyi00 9e6f3b8
test: update test code
songyi00 b429ff9
chore: update delete query
songyi00 63158d9
refactor: refactor portfolio stock domain
songyi00 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
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
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
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
36 changes: 36 additions & 0 deletions
36
batch/src/main/java/nexters/payout/batch/application/PortfolioBatchService.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,36 @@ | ||
package nexters.payout.batch.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import nexters.payout.domain.portfolio.domain.Portfolio; | ||
import nexters.payout.domain.portfolio.domain.repository.PortfolioRepository; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional | ||
public class PortfolioBatchService { | ||
|
||
private final PortfolioRepository portfolioRepository; | ||
|
||
@Scheduled(cron = "${schedules.cron.portfolio}", zone = "UTC") | ||
void deletePortfolio() { | ||
log.info("delete portfolio start.."); | ||
portfolioRepository.deleteAllByIdInQuery(getExpiredPortfolioIds()); | ||
log.info("delete portfolio end.."); | ||
} | ||
|
||
private List<UUID> getExpiredPortfolioIds() { | ||
return portfolioRepository.findByExpireAtBefore(Instant.now()) | ||
.stream() | ||
.map(Portfolio::getId) | ||
.toList(); | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
...s/payout/batch/application/StockLogo.java → ...t/batch/application/client/StockLogo.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
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
2 changes: 1 addition & 1 deletion
2
batch/src/main/java/nexters/payout/batch/infra/fmp/FmpFinancialClient.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
2 changes: 1 addition & 1 deletion
2
batch/src/main/java/nexters/payout/batch/infra/ninjas/NinjasFinancialClient.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
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
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
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ spring: | |
schedules: | ||
cron: | ||
stock: "-" | ||
portfolio: "-" | ||
dividend: | ||
past: "-" | ||
future: "-" |
1 change: 1 addition & 0 deletions
1
batch/src/test/java/nexters/payout/batch/application/DividendBatchServiceTest.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
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
45 changes: 45 additions & 0 deletions
45
batch/src/test/java/nexters/payout/batch/application/PortfolioBatchServiceTest.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,45 @@ | ||
package nexters.payout.batch.application; | ||
|
||
import nexters.payout.batch.common.AbstractBatchServiceTest; | ||
import nexters.payout.domain.PortfolioFixture; | ||
import nexters.payout.domain.portfolio.domain.Portfolio; | ||
import nexters.payout.domain.portfolio.domain.PortfolioStock; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
|
||
import static nexters.payout.domain.PortfolioFixture.STOCK_ID; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
class PortfolioBatchServiceTest extends AbstractBatchServiceTest { | ||
|
||
@Test | ||
void 만료기간이_지난_포트폴리오는_삭제한다() { | ||
// given | ||
portfolioRepository.save(PortfolioFixture.createPortfolio( | ||
Instant.now().minus(1, ChronoUnit.DAYS), | ||
List.of(new PortfolioStock(STOCK_ID, 1)) | ||
)); | ||
portfolioRepository.save(PortfolioFixture.createPortfolio( | ||
Instant.now().minus(2, ChronoUnit.DAYS), | ||
List.of(new PortfolioStock(STOCK_ID, 2)) | ||
)); | ||
Portfolio notExpiredPortfolio = portfolioRepository.save(PortfolioFixture.createPortfolio( | ||
Instant.now().plus(1, ChronoUnit.DAYS), | ||
List.of(new PortfolioStock(STOCK_ID, 1)) | ||
)); | ||
|
||
// when | ||
portfolioBatchService.deletePortfolio(); | ||
|
||
// then | ||
List<Portfolio> actual = portfolioRepository.findAll(); | ||
assertAll( | ||
() -> assertThat(actual).hasSize(1), | ||
() -> assertThat(actual.get(0)).isEqualTo(notExpiredPortfolio) | ||
); | ||
} | ||
} |
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
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
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
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
31 changes: 31 additions & 0 deletions
31
domain/src/main/java/nexters/payout/domain/portfolio/domain/PortfolioStocks.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,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); | ||
} | ||
} |
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
Oops, something went wrong.
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.
expired_at column을 이용해서 유효기간이 지난 포트폴리오를 제거하는 쿼리를 jpa에서 한번에 짜는 방식 (deleteAllByExpiredAftter~~)도 가능할 것 같은데 id 리스트 먼저 찾도록 하신 이유가 있으실까요???
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.
jpa에서
deleteAllBy
~ 를 사용하면 건 별로 삭제 쿼리가 날라가는 것으로 알고 있어서deleteAllById
를 사용하였는데 이것도 건 별로 삭제 쿼리가 날라가더라구요..?(방금 알았어요 😂)jpql 직접 생성하는 것으로 변경해놓겠습니다 👍