Skip to content
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

[bug] 포트폴리오 단일 삭제 문제 #83

Closed
yonghwankim-dev opened this issue Dec 13, 2023 · 0 comments · Fixed by #92
Closed

[bug] 포트폴리오 단일 삭제 문제 #83

yonghwankim-dev opened this issue Dec 13, 2023 · 0 comments · Fixed by #92
Assignees
Labels
bug Something isn't working

Comments

@yonghwankim-dev
Copy link
Member

yonghwankim-dev commented Dec 13, 2023

상황

포트폴리오 수익 내역(PortfolioGainHistory) 데이터가 존재한 상태에서 포트폴리오 삭제 API 요청(/api/portfolios/:portfolioId)시 버그가 발생합니다.

원인

포트폴리오 삭제 서비스 수행 중 포트폴리오 데이터 삭제전에 포트폴리오 수익 내역 데이터를 삭제하지 않아서 버그가 발생하였습니다.

@Transactional
public void deletePortfolio(Long portfolioId, AuthMember authMember) {
	log.info("포트폴리오 삭제 서비스 요청 : portfolioId={}, authMember={}", portfolioId, authMember);

	Portfolio findPortfolio = findPortfolio(portfolioId);
	validatePortfolioAuthorization(findPortfolio, authMember.getMemberId());

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

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

	int delPortfolioCnt = portfolioHoldingRepository.deleteAllByPortfolioId(findPortfolio.getId());
	log.info("포트폴리오 종목 삭제 개수 : {}", delPortfolioCnt);

	portfolioRepository.deleteById(findPortfolio.getId());
	log.info("포트폴리오 삭제 : delPortfolio={}", findPortfolio);
}

해결방법

portfolioRepository.deleteById() 메소드 호출전에 삭제하고자 하는 포트폴리오의 포트폴리오 수익 내역 데이터를 전부 삭제하는 코드를 구현합니다.

개선사항

테스트 코드에 샘플 데이터로 포트폴리오 수익 내역 데이터를 추가하고 테스트 통과가 될것.

@yonghwankim-dev yonghwankim-dev added the bug Something isn't working label Dec 13, 2023
@yonghwankim-dev yonghwankim-dev added this to the [BE] Sprint #10 milestone Dec 13, 2023
@yonghwankim-dev yonghwankim-dev self-assigned this Dec 13, 2023
yonghwankim-dev added a commit that referenced this issue Dec 27, 2023
@yonghwankim-dev yonghwankim-dev linked a pull request Dec 27, 2023 that will close this issue
yonghwankim-dev added a commit that referenced this issue Dec 27, 2023
yonghwankim-dev added a commit that referenced this issue Dec 28, 2023
* #90 fix: 포트폴리오 손익내역 삭제 추가로 버그 해결

* #83 fix: 변수명 변경

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

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

* #93 docs: redirect-uri 변경

* #93 docs: redirect-uri 변경

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

* #83 fix: 변수명 변경

* #90 test: 포트폴리오 테스트 코드 정리
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant