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

[feat] : 포트폴리오 즐겨찾기 추가 & 삭제 API 구현 #39

Merged
merged 8 commits into from
Jun 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,24 @@ public ResponseEntity<ApiResponse<PortfolioDto.EditPortfolioResponse>> editPortf
PortfolioDto.EditPortfolioResponse editPortfolioResponse = portfolioService.editPortfolio(authorizationHeader, editPortfolioRequest);
return ApiResponse.onSuccess(SuccessStatus.SUCCESS_EDIT_PORTFOLIO, editPortfolioResponse);
}

// 포트폴리오 즐겨찾기 추가 API
@PostMapping("/bookmark")
public ResponseEntity<ApiResponse<Object>> 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<ApiResponse<Object>> removePortfolioBookMark(
@RequestHeader("Authorization") String authorizationHeader,
@RequestParam("portfolio_id") String portfolioId) {

portfolioService.removePortfolioBookMark(authorizationHeader, portfolioId);
return ApiResponse.onSuccess(SuccessStatus.SUCCESS_DELETE_PORTFOLIO_SCRAP);
}
}
12 changes: 12 additions & 0 deletions backend/src/main/java/org/dgu/backend/domain/Portfolio.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading