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

♻️ [Refactor] PortfolioService 에러 처리 추가 #45

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PortfolioService {
@Transactional
public PortfolioDetailDto createPortfolio(Long userId, PortfolioRequestDto requestDto) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new IllegalArgumentException("User not found with ID: " + userId));
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));

Experience experience = new Experience(
requestDto.getExperience().getSituation(),
Expand Down Expand Up @@ -82,7 +82,11 @@ public PortfolioDetailDto getPortfolioDetail(Long userId, Long portfolioId) {
@Transactional
public PortfolioDetailDto updatePortfolio(Long userId, Long portfolioId, PortfolioRequestDto requestDto) {
Portfolio portfolio = portfolioRepository.findPortfolioWithDetails(portfolioId, userId)
.orElseThrow(() -> new IllegalArgumentException("Portfolio not found or access denied for ID: " + portfolioId));
.orElseThrow(() -> new CustomException(ErrorCode.PORTFOLIO_NOT_FOUND));

if (!portfolio.getUser().getUserId().equals(userId)) {
throw new CustomException(ErrorCode.PORTFOLIO_ACCESS_FORBIDDEN);
}

portfolio.update(
requestDto.getName(),
Expand Down Expand Up @@ -112,7 +116,11 @@ public PortfolioDetailDto updatePortfolio(Long userId, Long portfolioId, Portfol
@Transactional
public void deletePortfolio(Long userId, Long portfolioId) {
Portfolio portfolio = portfolioRepository.findPortfolioWithDetails(portfolioId, userId)
.orElseThrow(() -> new IllegalArgumentException("Portfolio not found or access denied for ID: " + portfolioId));
.orElseThrow(() -> new CustomException(ErrorCode.PORTFOLIO_NOT_FOUND));

if (!portfolio.getUser().getUserId().equals(userId)) {
throw new CustomException(ErrorCode.PORTFOLIO_ACCESS_FORBIDDEN);
}

portfolioRepository.delete(portfolio);
}
Expand Down
Loading