Skip to content

Commit

Permalink
Fix: 에러 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
saokiritoni committed Dec 3, 2024
1 parent 80a8ba7 commit c82c621
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit c82c621

Please sign in to comment.