Skip to content

Commit

Permalink
[fix] 포트폴리오 단일 삭제 문제 해결 (#92)
Browse files Browse the repository at this point in the history
* #90 fix: 포트폴리오 손익내역 삭제 추가로 버그 해결

* #83 fix: 변수명 변경

* #90 test: 포트폴리오 테스트 코드 정리

* [docs] redirect uri 변경 (#94)

* #93 docs: redirect-uri 변경

* #93 docs: redirect-uri 변경

* #90 fix: 포트폴리오 손익내역 삭제 추가로 버그 해결

* #83 fix: 변수명 변경

* #90 test: 포트폴리오 테스트 코드 정리
  • Loading branch information
yonghwankim-dev committed Dec 28, 2023
1 parent f28496c commit 938d6bb
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ Optional<PortfolioGainHistory> findFirstByPortfolioAndCreateAtIsLessThanEqualOrd
@Param("portfolioId") Long portfolioId, @Param("createAt") LocalDateTime createAt);

List<PortfolioGainHistory> findAllByPortfolioId(Long portfolioId);

int deleteAllByPortfolioId(Long portfolioId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import codesquad.fineants.spring.api.errors.exception.ConflictException;
import codesquad.fineants.spring.api.errors.exception.ForBiddenException;
import codesquad.fineants.spring.api.errors.exception.NotFoundResourceException;
import codesquad.fineants.spring.api.kis.KisService;
import codesquad.fineants.spring.api.kis.manager.CurrentPriceManager;
import codesquad.fineants.spring.api.portfolio.request.PortfolioCreateRequest;
import codesquad.fineants.spring.api.portfolio.request.PortfolioModifyRequest;
Expand All @@ -47,7 +46,6 @@ public class PortFolioService {
private final PurchaseHistoryRepository purchaseHistoryRepository;
private final PortfolioGainHistoryRepository portfolioGainHistoryRepository;
private final CurrentPriceManager currentPriceManager;
private final KisService kisService;

@Transactional
public PortFolioCreateResponse addPortFolio(PortfolioCreateRequest request, AuthMember authMember) {
Expand Down Expand Up @@ -117,11 +115,14 @@ public void deletePortfolio(Long portfolioId, AuthMember authMember) {
Portfolio findPortfolio = findPortfolio(portfolioId);
validatePortfolioAuthorization(findPortfolio, authMember.getMemberId());

List<Long> portfolioStockIds = portfolioHoldingRepository.findAllByPortfolio(findPortfolio).stream()
List<Long> portfolioHoldingIds = portfolioHoldingRepository.findAllByPortfolio(findPortfolio).stream()
.map(PortfolioHolding::getId)
.collect(Collectors.toList());

int delTradeHistoryCnt = purchaseHistoryRepository.deleteAllByPortfolioHoldingIdIn(portfolioStockIds);
int delPortfolioGainHistoryCnt = portfolioGainHistoryRepository.deleteAllByPortfolioId(portfolioId);
log.info("포트폴리오 손익 내역 삭제 개수 : {}", delPortfolioGainHistoryCnt);

int delTradeHistoryCnt = purchaseHistoryRepository.deleteAllByPortfolioHoldingIdIn(portfolioHoldingIds);
log.info("매매이력 삭제 개수 : {}", delTradeHistoryCnt);

int delPortfolioCnt = portfolioHoldingRepository.deleteAllByPortfolioId(findPortfolio.getId());
Expand Down
Loading

0 comments on commit 938d6bb

Please sign in to comment.