Skip to content

Commit

Permalink
Merge pull request #45 from CSID-DGU/develop
Browse files Browse the repository at this point in the history
♻️ [Refactor] PortfolioService 에러 처리 추가
  • Loading branch information
saokiritoni authored Dec 3, 2024
2 parents 12acf5e + c82c621 commit 99c84a7
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 99c84a7

Please sign in to comment.