Skip to content

Commit

Permalink
Merge pull request #31 from CSID-DGU/feature/#21/portfolio
Browse files Browse the repository at this point in the history
[feat] : 포트폴리오 정보 수정 API 구현 (PATCH)
  • Loading branch information
bbbang105 authored May 27, 2024
2 parents 3abe924 + d489904 commit df799e8
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum SuccessStatus implements BaseCode {
// Portfolio
SUCCESS_GET_PORTFOLIOS(HttpStatus.OK, "200", "포트폴리오 조회에 성공했습니다."),
SUCCESS_GET_PORTFOLIO_DETAILS(HttpStatus.OK, "200", "포트폴리오 상세 조회에 성공했습니다."),
SUCCESS_DELETE_PORTFOLIO(HttpStatus.OK, "200", "포트폴리오 삭제에 성공했습니다.");
SUCCESS_DELETE_PORTFOLIO(HttpStatus.OK, "200", "포트폴리오 삭제에 성공했습니다."),
SUCCESS_EDIT_PORTFOLIO(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 @@ -44,4 +44,14 @@ public ResponseEntity<ApiResponse<Object>> removePortfolio(
portfolioService.removePortfolio(authorizationHeader, portfolioId);
return ApiResponse.onSuccess(SuccessStatus.SUCCESS_DELETE_PORTFOLIO);
}

// 포트폴리오 정보 수정 API
@PatchMapping
public ResponseEntity<ApiResponse<PortfolioDto.EditPortfolioResponse>> editPortfolio(
@RequestHeader("Authorization") String authorizationHeader,
@RequestBody PortfolioDto.EditPortfolioRequest editPortfolioRequest) {

PortfolioDto.EditPortfolioResponse editPortfolioResponse = portfolioService.editPortfolio(authorizationHeader, editPortfolioRequest);
return ApiResponse.onSuccess(SuccessStatus.SUCCESS_EDIT_PORTFOLIO, editPortfolioResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.dgu.backend.common.BaseEntity;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Table(name = "performance_results")
public class PerformanceResult {
public class PerformanceResult extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "performance_results_id")
Expand Down
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 @@ -71,4 +71,16 @@ public void savePortfolio(String comment) {
isSaved = 1;
savedAt = LocalDateTime.now();
}

public void updateTitle(String title) {
this.title = title;
}

public void updateDescription(String description) {
this.description = description;
}

public void updateComment(String comment) {
this.comment = comment;
}
}
34 changes: 34 additions & 0 deletions backend/src/main/java/org/dgu/backend/dto/PortfolioDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.dgu.backend.domain.Portfolio;

import java.util.UUID;

Expand Down Expand Up @@ -38,4 +39,37 @@ public static class PortfolioDetailInfos {
private BackTestingDto.Trading trading;
private BackTestingDto.Performance performance;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class EditPortfolioRequest {
private String portfolioId;
private String title;
private String description;
private String comment;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class EditPortfolioResponse {
private String title;
private String description;
private String comment;

public static PortfolioDto.EditPortfolioResponse of(Portfolio portfolio) {
return EditPortfolioResponse.builder()
.title(portfolio.getTitle())
.description(portfolio.getDescription())
.comment(portfolio.getComment())
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface PortfolioService {
List<PortfolioDto.PortfolioInfos> getPortfolios(String authorizationHeader);
PortfolioDto.PortfolioDetailInfos getPortfolioDetails(String authorizationHeader, String portfolioId);
void removePortfolio(String authorizationHeader, String portfolioId);
PortfolioDto.EditPortfolioResponse editPortfolio(String authorizationHeader, PortfolioDto.EditPortfolioRequest editPortfolioRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ public void removePortfolio(String authorizationHeader, String portfolioId) {
portfolioRepository.delete(portfolio);
}

// 포트폴리오 정보를 수정하는 메서드
@Override
public PortfolioDto.EditPortfolioResponse editPortfolio(String authorizationHeader, PortfolioDto.EditPortfolioRequest editPortfolioRequest) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Portfolio portfolio = portfolioRepository.findByUserAndPortfolioId(user, UUID.fromString(editPortfolioRequest.getPortfolioId()))
.orElseThrow(() -> new PortfolioException(PortfolioErrorResult.NOT_FOUND_PORTFOLIO));

if (!Objects.isNull(editPortfolioRequest.getTitle())) {
portfolio.updateTitle(editPortfolioRequest.getTitle());
}

if (!Objects.isNull(editPortfolioRequest.getDescription())) {
portfolio.updateDescription(editPortfolioRequest.getDescription());
}

if (!Objects.isNull(editPortfolioRequest.getComment())) {
portfolio.updateComment(editPortfolioRequest.getComment());
}

portfolioRepository.save(portfolio);

return PortfolioDto.EditPortfolioResponse.of(portfolio);
}

// 거래 결과 응답 객체를 만드는 메서드
private BackTestingDto.Trading createTradingResultResponse(TradingResult tradingResult) {
return BackTestingDto.Trading.builder()
Expand Down

0 comments on commit df799e8

Please sign in to comment.