diff --git a/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java b/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java index d5a4f4e..cdd6509 100644 --- a/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java +++ b/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java @@ -26,7 +26,9 @@ public enum SuccessStatus implements BaseCode { SUCCESS_GET_PORTFOLIOS(HttpStatus.OK, "200", "포트폴리오 조회에 성공했습니다."), SUCCESS_GET_PORTFOLIO_DETAILS(HttpStatus.OK, "200", "포트폴리오 상세 조회에 성공했습니다."), SUCCESS_DELETE_PORTFOLIO(HttpStatus.OK, "200", "포트폴리오 삭제에 성공했습니다."), - SUCCESS_EDIT_PORTFOLIO(HttpStatus.OK, "200", "포트폴리오 정보 수정에 성공했습니다."); + SUCCESS_EDIT_PORTFOLIO(HttpStatus.OK, "200", "포트폴리오 정보 수정에 성공했습니다."), + SUCCESS_ADD_PORTFOLIO_SCRAP(HttpStatus.CREATED, "201", "포트폴리오 즐겨찾기 추가에 성공했습니다."), + SUCCESS_DELETE_PORTFOLIO_SCRAP(HttpStatus.OK, "200", "포트폴리오 즐겨찾기 삭제에 성공했습니다."); private final HttpStatus httpStatus; private final String code; diff --git a/backend/src/main/java/org/dgu/backend/controller/PortfolioController.java b/backend/src/main/java/org/dgu/backend/controller/PortfolioController.java index 165765e..a454e5e 100644 --- a/backend/src/main/java/org/dgu/backend/controller/PortfolioController.java +++ b/backend/src/main/java/org/dgu/backend/controller/PortfolioController.java @@ -54,4 +54,24 @@ public ResponseEntity> editPortf PortfolioDto.EditPortfolioResponse editPortfolioResponse = portfolioService.editPortfolio(authorizationHeader, editPortfolioRequest); return ApiResponse.onSuccess(SuccessStatus.SUCCESS_EDIT_PORTFOLIO, editPortfolioResponse); } + + // 포트폴리오 즐겨찾기 추가 API + @PostMapping("/bookmark") + public ResponseEntity> addPortfolioBookMark( + @RequestHeader("Authorization") String authorizationHeader, + @RequestParam("portfolio_id") String portfolioId) { + + portfolioService.addPortfolioBookMark(authorizationHeader, portfolioId); + return ApiResponse.onSuccess(SuccessStatus.SUCCESS_ADD_PORTFOLIO_SCRAP); + } + + // 포트폴리오 즐겨찾기 삭제 API + @DeleteMapping("/bookmark") + public ResponseEntity> removePortfolioBookMark( + @RequestHeader("Authorization") String authorizationHeader, + @RequestParam("portfolio_id") String portfolioId) { + + portfolioService.removePortfolioBookMark(authorizationHeader, portfolioId); + return ApiResponse.onSuccess(SuccessStatus.SUCCESS_DELETE_PORTFOLIO_SCRAP); + } } \ No newline at end of file diff --git a/backend/src/main/java/org/dgu/backend/domain/Portfolio.java b/backend/src/main/java/org/dgu/backend/domain/Portfolio.java index bf02107..d262cf8 100644 --- a/backend/src/main/java/org/dgu/backend/domain/Portfolio.java +++ b/backend/src/main/java/org/dgu/backend/domain/Portfolio.java @@ -48,6 +48,9 @@ public class Portfolio extends BaseEntity { @Column(name = "is_saved", nullable = false, length = 1) private int isSaved; + @Column(name = "is_marked", nullable = false) + private Boolean isMarked; + @OneToOne(mappedBy = "portfolio", cascade = CascadeType.ALL, orphanRemoval = true) private PortfolioOption portfolioOption; @@ -64,6 +67,7 @@ public Portfolio(User user, String title, String description) { this.title = title; this.description = description; this.isSaved = 0; + this.isMarked = false; } public void savePortfolio(String comment) { @@ -76,6 +80,14 @@ public void updateTitle(String title) { this.title = title; } + public void addBookMark() { + this.isMarked = true; + } + + public void removeBookMark() { + this.isMarked = false; + } + public void updateDescription(String description) { this.description = description; } diff --git a/backend/src/main/java/org/dgu/backend/service/PortfolioService.java b/backend/src/main/java/org/dgu/backend/service/PortfolioService.java index 175cb56..917907b 100644 --- a/backend/src/main/java/org/dgu/backend/service/PortfolioService.java +++ b/backend/src/main/java/org/dgu/backend/service/PortfolioService.java @@ -9,4 +9,6 @@ public interface PortfolioService { PortfolioDto.PortfolioDetailInfos getPortfolioDetails(String authorizationHeader, String portfolioId); void removePortfolio(String authorizationHeader, String portfolioId); PortfolioDto.EditPortfolioResponse editPortfolio(String authorizationHeader, PortfolioDto.EditPortfolioRequest editPortfolioRequest); + void addPortfolioBookMark(String authorizationHeader, String portfolioId); + void removePortfolioBookMark(String authorizationHeader, String portfolioId); } \ No newline at end of file diff --git a/backend/src/main/java/org/dgu/backend/service/PortfolioServiceImpl.java b/backend/src/main/java/org/dgu/backend/service/PortfolioServiceImpl.java index b3e2256..7c16c9e 100644 --- a/backend/src/main/java/org/dgu/backend/service/PortfolioServiceImpl.java +++ b/backend/src/main/java/org/dgu/backend/service/PortfolioServiceImpl.java @@ -92,4 +92,28 @@ public PortfolioDto.EditPortfolioResponse editPortfolio(String authorizationHead return PortfolioDto.EditPortfolioResponse.of(portfolio); } + + // 포트폴리오 즐겨찾기를 추가하는 메서드 + @Override + public void addPortfolioBookMark(String authorizationHeader, String portfolioId) { + User user = jwtUtil.getUserFromHeader(authorizationHeader); + + Portfolio portfolio = portfolioRepository.findByUserAndPortfolioId(user, UUID.fromString(portfolioId)) + .orElseThrow(() -> new PortfolioException(PortfolioErrorResult.NOT_FOUND_PORTFOLIO)); + + portfolio.addBookMark(); + portfolioRepository.save(portfolio); + } + + // 포트폴리오 즐겨찾기를 삭제하는 메서드 + @Override + public void removePortfolioBookMark(String authorizationHeader, String portfolioId) { + User user = jwtUtil.getUserFromHeader(authorizationHeader); + + Portfolio portfolio = portfolioRepository.findByUserAndPortfolioId(user, UUID.fromString(portfolioId)) + .orElseThrow(() -> new PortfolioException(PortfolioErrorResult.NOT_FOUND_PORTFOLIO)); + + portfolio.removeBookMark(); + portfolioRepository.save(portfolio); + } } \ No newline at end of file