Skip to content

Commit

Permalink
[#197] feat: Portfolio 삭제 API 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
jinnxyoung committed Sep 5, 2024
1 parent 57f9b96 commit d8bb126
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -43,4 +44,12 @@ public ApplicationResponse<PortfolioRes> updatePortfolio(@PathVariable("portfoli

return ApplicationResponse.ok(portfolioRes);
}

@Operation(description = "포트폴리오 삭제 API")
@DeleteMapping("/{portfolio_id}")
public ApplicationResponse<Void> deletePortfolio(@PathVariable("portfolio_id") Long portfolioId) {
portfolioService.deletePortfolio(portfolioId);

return ApplicationResponse.ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public Portfolio registerPortfolio(PortfolioReq portfolioReq) {
@Transactional
public Portfolio searchPortfolio(Long portfolioId) {
return portfolioRepository.findById(portfolioId)
.orElseThrow(() -> new IllegalArgumentException("해당 ID를 가진 포트폴리오가 없습니다: " + portfolioId));
.orElseThrow(() -> new IllegalArgumentException("해당 ID를 가진 포트폴리오가 없습니다. : " + portfolioId));
}

@Transactional
public Portfolio updatePortfolio(Long portfolioId, PortfolioReq portfolioReq) {
Portfolio portfolio = portfolioRepository.findById(portfolioId)
.orElseThrow(() -> new IllegalArgumentException("해당 ID를 가진 포트폴리오가 없습니다: " + portfolioId));
.orElseThrow(() -> new IllegalArgumentException("해당 ID를 가진 포트폴리오가 없습니다. : " + portfolioId));

PortfolioData currentData = portfolio.getPortfolioData();

Expand Down Expand Up @@ -170,4 +170,11 @@ public Portfolio updatePortfolio(Long portfolioId, PortfolioReq portfolioReq) {

return portfolioRepository.save(portfolio);
}

@Transactional
public void deletePortfolio(Long portfolioId) {
Portfolio portfolio = portfolioRepository.findById(portfolioId)
.orElseThrow(() -> new IllegalArgumentException("해당 ID를 가진 포트폴리오가 없습니다. : " + portfolioId));
portfolioRepository.delete(portfolio);
}
}

0 comments on commit d8bb126

Please sign in to comment.