From 25b65c3a5b98004f65ca64e28925ea49c4cb6bf2 Mon Sep 17 00:00:00 2001 From: haweeee Date: Fri, 2 Aug 2024 22:36:39 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=EB=A7=A4=EB=A7=A4=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=A1=B0=ED=9A=8C=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BackTestRepository.java | 8 +++++ .../SalesTransactionHistoryConverter.java | 24 ++++++++++++++ .../dto/request/SalesHistoryRequestDto.java | 7 ++++ .../dto/response/SalesHistoryResponseDto.java | 32 +++++++++++++++++++ .../SalesTransactionHistoryRepository.java | 11 +++++++ .../SalesTransactionHistoryService.java | 27 ++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java create mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/SalesHistoryRequestDto.java create mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java create mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java create mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java diff --git a/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java b/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java index d1879dd..4e85ad9 100644 --- a/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java +++ b/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java @@ -1,5 +1,6 @@ package com.quantweb.springserver.domain.back_test.repository; +<<<<<<< HEAD import org.springframework.data.jpa.repository.JpaRepository; import com.quantweb.springserver.domain.back_test.entity.BackTest; @@ -10,6 +11,13 @@ public interface BackTestRepository extends JpaRepository { Boolean existsByName(String name); +======= +import com.quantweb.springserver.domain.back_test.entity.BackTest; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BackTestRepository extends JpaRepository { + +>>>>>>> e46edb7 (feat: 매매내역 조회하기) Optional> findAllByUserId(Long userId); diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java new file mode 100644 index 0000000..92b3914 --- /dev/null +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java @@ -0,0 +1,24 @@ +package com.quantweb.springserver.domain.sales_transaction_history.converter; + +import com.quantweb.springserver.domain.sales_transaction_history.dto.response.SalesHistoryResponseDto; +import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; + +public class SalesTransactionHistoryConverter { + + public static SalesHistoryResponseDto toHistoryResponseDto(SalesTransactionHistory history){ + + return SalesHistoryResponseDto.builder() +// .transactionDate() +// .stockName() +// .period() +// .realizedProfit() +// .profitPercentage() +// .buyQuantity() +// .sellQuantity() +// .buyPrice() +// .sellPrice() +// .status() +// .fee() + .build(); + } +} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/SalesHistoryRequestDto.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/SalesHistoryRequestDto.java new file mode 100644 index 0000000..15b22ca --- /dev/null +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/SalesHistoryRequestDto.java @@ -0,0 +1,7 @@ +package com.quantweb.springserver.domain.sales_transaction_history.dto.request; + + +public class SalesHistoryRequestDto { + + +} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java new file mode 100644 index 0000000..804cbe7 --- /dev/null +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java @@ -0,0 +1,32 @@ +package com.quantweb.springserver.domain.sales_transaction_history.dto.response; + +import com.quantweb.springserver.domain.sales_transaction_history.entity.TransactionType; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +public class SalesHistoryResponseDto { + /** + * 용어가 헷갈리는게 많아서 erd 수정할 때 설명란에 자세히 적어야할 것 같습니다. + * **/ + + private LocalDateTime transactionDate; //거래일시 + private String stockName; //종목 + private LocalDateTime period; //평균보유기간 + private Integer realizedProfit; //실현손익 + private Float profitPercentage; //수익률 + private Float buyQuantity; //매수수량 + private Float sellQuantity; //매도수량 + private Integer buyPrice; //매수금액 + private Integer sellPrice; //매도금액 + private TransactionType status; //상태: 거래완료 + private Integer fee; //수수료 + +} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java new file mode 100644 index 0000000..143634c --- /dev/null +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java @@ -0,0 +1,11 @@ +package com.quantweb.springserver.domain.sales_transaction_history.repository; + +import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface SalesTransactionHistoryRepository extends JpaRepository { + + Optional findByBackTestId(Long backTestId); +} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java new file mode 100644 index 0000000..a5691f9 --- /dev/null +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java @@ -0,0 +1,27 @@ +package com.quantweb.springserver.domain.sales_transaction_history.service; + +import com.quantweb.springserver.domain.back_test.repository.BackTestRepository; +import com.quantweb.springserver.domain.sales_transaction_history.converter.SalesTransactionHistoryConverter; +import com.quantweb.springserver.domain.sales_transaction_history.dto.response.SalesHistoryResponseDto; +import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; +import com.quantweb.springserver.domain.sales_transaction_history.repository.SalesTransactionHistoryRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class SalesTransactionHistoryService { + + private final SalesTransactionHistoryRepository salesTransactionHistoryRepository; + private final BackTestRepository backTestRepository; + + public SalesHistoryResponseDto getSalesTransactionHistory(Long backtestId){ + + SalesTransactionHistory findHistory = salesTransactionHistoryRepository.findByBackTestId(backtestId).orElseThrow(); + + return SalesTransactionHistoryConverter.toHistoryResponseDto(findHistory); + } + +} From 23f85a27621468964edf1a80df50c6ec975facd1 Mon Sep 17 00:00:00 2001 From: haweeee Date: Fri, 2 Aug 2024 22:48:33 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=EC=9D=91=EB=8B=B5=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/SalesTransactionHistoryConverter.java | 5 +++++ .../dto/response/SalesHistoryResponseDto.java | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java index 92b3914..409eb51 100644 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java @@ -3,10 +3,14 @@ import com.quantweb.springserver.domain.sales_transaction_history.dto.response.SalesHistoryResponseDto; import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; +import java.util.List; + public class SalesTransactionHistoryConverter { public static SalesHistoryResponseDto toHistoryResponseDto(SalesTransactionHistory history){ + List graph; + return SalesHistoryResponseDto.builder() // .transactionDate() // .stockName() @@ -19,6 +23,7 @@ public static SalesHistoryResponseDto toHistoryResponseDto(SalesTransactionHisto // .sellPrice() // .status() // .fee() + .transactionHistoryGraph(graph) .build(); } } diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java index 804cbe7..7e52734 100644 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import java.time.LocalDateTime; +import java.util.List; @NoArgsConstructor @AllArgsConstructor @@ -29,4 +30,16 @@ public class SalesHistoryResponseDto { private TransactionType status; //상태: 거래완료 private Integer fee; //수수료 + private List transactionHistoryGraph; //매매내역 - 그래프 + + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Builder + public static class TransactionHistoryGraph { + private LocalDateTime date; + private Integer amount; + private Boolean action; + private String ticker; + } } From a570f524f89de5c19a113920c2c228e5987ef0d3 Mon Sep 17 00:00:00 2001 From: haweeee Date: Sun, 11 Aug 2024 17:40:45 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EB=A7=A4=EB=A7=A4=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=A1=B0=ED=9A=8C=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BackTestController.java | 28 ++++++++++- .../converter/BackTestConverter.java | 18 +------ .../repository/BackTestRepository.java | 12 +---- .../SalesTransactionHistoryConverter.java | 29 ----------- .../TransactionHistoryConverter.java | 43 ++++++++++++++++ ...java => TransactionHistoryRequestDto.java} | 2 +- .../dto/response/SalesHistoryResponseDto.java | 45 ----------------- .../TransactionHistoryResponseDto.java | 50 +++++++++++++++++++ .../SalesTransactionHistoryRepository.java | 11 ---- .../TransactionHistoryRepository.java | 5 ++ .../SalesTransactionHistoryService.java | 27 ---------- .../service/TransactionHistoryService.java | 9 ++++ 12 files changed, 138 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java rename src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/{SalesHistoryRequestDto.java => TransactionHistoryRequestDto.java} (66%) delete mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java create mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/TransactionHistoryResponseDto.java delete mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java delete mode 100644 src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java diff --git a/src/main/java/com/quantweb/springserver/domain/back_test/controller/BackTestController.java b/src/main/java/com/quantweb/springserver/domain/back_test/controller/BackTestController.java index 67add89..b1d5730 100644 --- a/src/main/java/com/quantweb/springserver/domain/back_test/controller/BackTestController.java +++ b/src/main/java/com/quantweb/springserver/domain/back_test/controller/BackTestController.java @@ -8,6 +8,10 @@ import com.quantweb.springserver.domain.stock.dto.response.StockResponseDto; import com.quantweb.springserver.domain.stock.service.StockService; + +import com.quantweb.springserver.domain.sales_transaction_history.dto.response.TransactionHistoryResponseDto; +import com.quantweb.springserver.domain.sales_transaction_history.service.TransactionHistoryService; + import org.springframework.web.bind.annotation.*; import com.quantweb.springserver.domain.auth.config.Authenticated; @@ -35,6 +39,7 @@ public class BackTestController { private final BackTestService backTestService; private final StockService stockService; + private final TransactionHistoryService transactionHistoryService; @PostMapping("/{userId}") @Operation(summary = "백테스트 실행하기 API",description = "") @@ -43,8 +48,8 @@ public class BackTestController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "BACKTEST400", description = "백테스트 이름이 중복되었습니다.",content = @Content(schema = @Schema(implementation = EntityResponse.class))), }) @Authenticated - public Object backTest(@AuthenticationPrincipal @PathVariable("userId") Long userId, @RequestBody BackTestInput backTestInput) { - return backTestService.backtestAndSave(userId, backTestInput); + public ResponseEntity backTest(@AuthenticationPrincipal @PathVariable("userId") Long userId, @RequestBody BackTestInput backTestInput) { + return ResponseEntity.ok(backTestService.backtestAndSave(userId, backTestInput)); } @GetMapping("/{backtestId}/details") @@ -57,6 +62,7 @@ public Object backTest(@AuthenticationPrincipal @PathVariable("userId") Long use @Parameter(name = "backtestId", description = "조회할 백테스트 Id"), }) + @Authenticated public ResponseEntity getResultDetails(@PathVariable("backtestId") Long backtestId){ BackTestDetailsDto.GetBackTestDto resultDto = backTestService.getDetailsResult(backtestId); @@ -101,4 +107,22 @@ public ResponseEntity> getMyBacktests(@PathVariable("u return ResponseEntity.ok(resultDto); } + @GetMapping("/{backtestId}/histories") + @Operation(summary = "백테스트 매매내역 조회 API",description = "") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "BACKTEST404", description = "백테스트가 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = EntityResponse.class))), + }) + @Parameters({ + @Parameter(name = "backtestId", description = "조회할 백테스트 Id"), + + }) + @Authenticated + public ResponseEntity getTrasactionHistory(@PathVariable("backtestId") Long backtestId){ + + TransactionHistoryResponseDto resultDto = transactionHistoryService.getTransactionHistory(backtestId); + + return ResponseEntity.ok(resultDto); + } + } diff --git a/src/main/java/com/quantweb/springserver/domain/back_test/converter/BackTestConverter.java b/src/main/java/com/quantweb/springserver/domain/back_test/converter/BackTestConverter.java index 04d23de..c7fdc40 100644 --- a/src/main/java/com/quantweb/springserver/domain/back_test/converter/BackTestConverter.java +++ b/src/main/java/com/quantweb/springserver/domain/back_test/converter/BackTestConverter.java @@ -43,24 +43,10 @@ public static BackTest toBackTest(User user, BackTestInput backTestInput, Invest .build(); } -// public static BackTestDetailsDto.BackTestResponseDto toBackTestResultDto(BackTest backTest){ -// -// return BackTestDetailsDto.BackTestResponseDto.builder() -//// .accumulatedProfit(backTest.getRealizedProfit()) -//// .mdd() -//// .totalAssest() -//// .initInvestFund() -//// .evaluatedProfit() -//// .realizedProfit() -//// .marketShared() -//// .investCategories() -// .build(); -// } - public static BackTestDetailsDto.GetBackTestDto toBackTestResultDto(BackTest backTest, - List dailyPercentages, List dailyPercentageUs500s, - List mdds, List mddUs500s){ + List dailyPercentages, List dailyPercentageUs500s, + List mdds, List mddUs500s){ BackTestDetailsDto.GetBackTestDto.DailyCumulativeReturn dailyCumulativeReturn = toDailyCumulativeReturn(dailyPercentages, dailyPercentageUs500s); diff --git a/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java b/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java index 4e85ad9..ffe5c1d 100644 --- a/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java +++ b/src/main/java/com/quantweb/springserver/domain/back_test/repository/BackTestRepository.java @@ -1,6 +1,6 @@ package com.quantweb.springserver.domain.back_test.repository; -<<<<<<< HEAD + import org.springframework.data.jpa.repository.JpaRepository; import com.quantweb.springserver.domain.back_test.entity.BackTest; @@ -11,14 +11,6 @@ public interface BackTestRepository extends JpaRepository { Boolean existsByName(String name); -======= -import com.quantweb.springserver.domain.back_test.entity.BackTest; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface BackTestRepository extends JpaRepository { - ->>>>>>> e46edb7 (feat: 매매내역 조회하기) - Optional> findAllByUserId(Long userId); -} \ No newline at end of file +} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java deleted file mode 100644 index 409eb51..0000000 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/SalesTransactionHistoryConverter.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.quantweb.springserver.domain.sales_transaction_history.converter; - -import com.quantweb.springserver.domain.sales_transaction_history.dto.response.SalesHistoryResponseDto; -import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; - -import java.util.List; - -public class SalesTransactionHistoryConverter { - - public static SalesHistoryResponseDto toHistoryResponseDto(SalesTransactionHistory history){ - - List graph; - - return SalesHistoryResponseDto.builder() -// .transactionDate() -// .stockName() -// .period() -// .realizedProfit() -// .profitPercentage() -// .buyQuantity() -// .sellQuantity() -// .buyPrice() -// .sellPrice() -// .status() -// .fee() - .transactionHistoryGraph(graph) - .build(); - } -} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/TransactionHistoryConverter.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/TransactionHistoryConverter.java index 99f2dc6..be55cfa 100644 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/TransactionHistoryConverter.java +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/converter/TransactionHistoryConverter.java @@ -2,10 +2,13 @@ import com.quantweb.springserver.domain.back_test.DTO.response.InvestmentResultDto; import com.quantweb.springserver.domain.back_test.entity.BackTest; +import com.quantweb.springserver.domain.sales_transaction_history.dto.response.TransactionHistoryResponseDto; import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; import com.quantweb.springserver.domain.sales_transaction_history.entity.TransactionType; import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; public class TransactionHistoryConverter { @@ -20,4 +23,44 @@ public static SalesTransactionHistory toTransactionHistory(InvestmentResultDto.T .investmentSimulation(null) .build(); } + + public static TransactionHistoryResponseDto.TransactionHistory toTransactionHistoryResult(SalesTransactionHistory transactionHistories){ + + return TransactionHistoryResponseDto.TransactionHistory.builder() +// .transactionDate(transactionHistories.getDateTime()) +// .stockName(transactionHistories.getTicker()) +// .period() +// .realizedProfit() +// .profitPercentage() +// .buyQuantity() +// .buyPrice() +// .sellQuantity() +// .sellPrice() +// .status() +// .fee() +// .transactionHistoryGraph() + .build(); + } + + public static TransactionHistoryResponseDto.TransactionHistoryGraph toTransactionHistoryGraph(SalesTransactionHistory transactionHistories){ + + return TransactionHistoryResponseDto.TransactionHistoryGraph.builder() + .date(transactionHistories.getDateTime()) + .amount(transactionHistories.getQuantity()) + .action(transactionHistories.getType()) + .ticker(transactionHistories.getTicker()) + .build(); + } + + public static TransactionHistoryResponseDto toTransactionHistoryResultDto(List transactionHistories){ + + List graphs = transactionHistories.stream() + .map(TransactionHistoryConverter::toTransactionHistoryGraph) + .toList(); + + return TransactionHistoryResponseDto.builder() + //.transactionHistories() + .transactionHistoryGraph(graphs) + .build(); + } } diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/SalesHistoryRequestDto.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/TransactionHistoryRequestDto.java similarity index 66% rename from src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/SalesHistoryRequestDto.java rename to src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/TransactionHistoryRequestDto.java index 15b22ca..f5c0764 100644 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/SalesHistoryRequestDto.java +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/request/TransactionHistoryRequestDto.java @@ -1,7 +1,7 @@ package com.quantweb.springserver.domain.sales_transaction_history.dto.request; -public class SalesHistoryRequestDto { +public class TransactionHistoryRequestDto { } diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java deleted file mode 100644 index 7e52734..0000000 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/SalesHistoryResponseDto.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.quantweb.springserver.domain.sales_transaction_history.dto.response; - -import com.quantweb.springserver.domain.sales_transaction_history.entity.TransactionType; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.time.LocalDateTime; -import java.util.List; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Builder -public class SalesHistoryResponseDto { - /** - * 용어가 헷갈리는게 많아서 erd 수정할 때 설명란에 자세히 적어야할 것 같습니다. - * **/ - - private LocalDateTime transactionDate; //거래일시 - private String stockName; //종목 - private LocalDateTime period; //평균보유기간 - private Integer realizedProfit; //실현손익 - private Float profitPercentage; //수익률 - private Float buyQuantity; //매수수량 - private Float sellQuantity; //매도수량 - private Integer buyPrice; //매수금액 - private Integer sellPrice; //매도금액 - private TransactionType status; //상태: 거래완료 - private Integer fee; //수수료 - - private List transactionHistoryGraph; //매매내역 - 그래프 - - @NoArgsConstructor - @AllArgsConstructor - @Getter - @Builder - public static class TransactionHistoryGraph { - private LocalDateTime date; - private Integer amount; - private Boolean action; - private String ticker; - } -} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/TransactionHistoryResponseDto.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/TransactionHistoryResponseDto.java new file mode 100644 index 0000000..2e8b4af --- /dev/null +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/dto/response/TransactionHistoryResponseDto.java @@ -0,0 +1,50 @@ +package com.quantweb.springserver.domain.sales_transaction_history.dto.response; + +import com.quantweb.springserver.domain.sales_transaction_history.entity.TransactionType; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +public class TransactionHistoryResponseDto { + + private List transactionHistories; + + private List transactionHistoryGraph; //매매내역 - 그래프 + + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Builder + public static class TransactionHistory { + private LocalDate transactionDate; //거래일시 + private String stockName; //종목 + private LocalDate period; //평균보유기간 + private Integer realizedProfit; //실현손익 + private Float profitPercentage; //수익률 + private Float buyQuantity; //매수수량 + private Float sellQuantity; //매도수량 + private Long buyPrice; //매수금액 + private Long sellPrice; //매도금액 + private TransactionType status; //상태: 거래완료 + private Integer fee; //수수료 + } + + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Builder + public static class TransactionHistoryGraph { + private LocalDate date; + private Long amount; + private TransactionType action; + private String ticker; + } +} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java deleted file mode 100644 index 143634c..0000000 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/SalesTransactionHistoryRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.quantweb.springserver.domain.sales_transaction_history.repository; - -import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface SalesTransactionHistoryRepository extends JpaRepository { - - Optional findByBackTestId(Long backTestId); -} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/TransactionHistoryRepository.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/TransactionHistoryRepository.java index e05042e..90fac03 100644 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/TransactionHistoryRepository.java +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/repository/TransactionHistoryRepository.java @@ -3,5 +3,10 @@ import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; + public interface TransactionHistoryRepository extends JpaRepository { + + Optional> findAllByBackTestId(Long backtestId); } diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java deleted file mode 100644 index a5691f9..0000000 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/SalesTransactionHistoryService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.quantweb.springserver.domain.sales_transaction_history.service; - -import com.quantweb.springserver.domain.back_test.repository.BackTestRepository; -import com.quantweb.springserver.domain.sales_transaction_history.converter.SalesTransactionHistoryConverter; -import com.quantweb.springserver.domain.sales_transaction_history.dto.response.SalesHistoryResponseDto; -import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; -import com.quantweb.springserver.domain.sales_transaction_history.repository.SalesTransactionHistoryRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class SalesTransactionHistoryService { - - private final SalesTransactionHistoryRepository salesTransactionHistoryRepository; - private final BackTestRepository backTestRepository; - - public SalesHistoryResponseDto getSalesTransactionHistory(Long backtestId){ - - SalesTransactionHistory findHistory = salesTransactionHistoryRepository.findByBackTestId(backtestId).orElseThrow(); - - return SalesTransactionHistoryConverter.toHistoryResponseDto(findHistory); - } - -} diff --git a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/TransactionHistoryService.java b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/TransactionHistoryService.java index bf35039..c22ab13 100644 --- a/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/TransactionHistoryService.java +++ b/src/main/java/com/quantweb/springserver/domain/sales_transaction_history/service/TransactionHistoryService.java @@ -3,12 +3,15 @@ import com.quantweb.springserver.domain.back_test.DTO.response.InvestmentResultDto; import com.quantweb.springserver.domain.back_test.entity.BackTest; import com.quantweb.springserver.domain.sales_transaction_history.converter.TransactionHistoryConverter; +import com.quantweb.springserver.domain.sales_transaction_history.dto.response.TransactionHistoryResponseDto; +import com.quantweb.springserver.domain.sales_transaction_history.entity.SalesTransactionHistory; import com.quantweb.springserver.domain.sales_transaction_history.repository.TransactionHistoryRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.List; @Service @RequiredArgsConstructor @@ -22,6 +25,12 @@ public void saveTransactionHistory(ArrayList { transactionHistoryRepository.save(TransactionHistoryConverter.toTransactionHistory(th, backTest)); }); + } + + public TransactionHistoryResponseDto getTransactionHistory(Long backtestId){ + + List transactionHistories = transactionHistoryRepository.findAllByBackTestId(backtestId).orElseThrow(() -> new RuntimeException("백테스트가 존재하지 않습니다.")); + return TransactionHistoryConverter.toTransactionHistoryResultDto(transactionHistories); } } From 2a0e480b1be5c9e08aa07303c9a709eecf930ce1 Mon Sep 17 00:00:00 2001 From: haweeee Date: Sat, 17 Aug 2024 17:59:22 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quantweb/springserver/common/entity/BaseTimeEntity.java | 4 ++-- .../domain/market/respository/MarketRepository.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/quantweb/springserver/common/entity/BaseTimeEntity.java b/src/main/java/com/quantweb/springserver/common/entity/BaseTimeEntity.java index 39faa18..b11c7f2 100644 --- a/src/main/java/com/quantweb/springserver/common/entity/BaseTimeEntity.java +++ b/src/main/java/com/quantweb/springserver/common/entity/BaseTimeEntity.java @@ -13,7 +13,7 @@ @EntityListeners(AuditingEntityListener.class) public abstract class BaseTimeEntity { - @CreatedDate private LocalDateTime createdDate; + @CreatedDate private LocalDateTime createdAt; - @LastModifiedDate private LocalDateTime modifiedDate; + @LastModifiedDate private LocalDateTime updatedAt; } diff --git a/src/main/java/com/quantweb/springserver/domain/market/respository/MarketRepository.java b/src/main/java/com/quantweb/springserver/domain/market/respository/MarketRepository.java index 00e379a..7211b94 100644 --- a/src/main/java/com/quantweb/springserver/domain/market/respository/MarketRepository.java +++ b/src/main/java/com/quantweb/springserver/domain/market/respository/MarketRepository.java @@ -24,10 +24,10 @@ public interface MarketRepository extends JpaRepository { @Query("SELECT m FROM Market m Join m.investmentSimulation i WHERE i.investStartDate >= :currentDate ORDER BY m.subscribeNum DESC") Page findAllInvestmentSimulationByRecommend(Pageable pageable); //마켓 백 테스트 전략 검색 - @Query("SELECT DISTINCT m FROM Market m JOIN m.marketTags t WHERE M.name LIKE%:keyword% OR t.tag LIKE%:keyword% AND m.investmentSimulation IS NULL") + @Query("SELECT DISTINCT m FROM Market m JOIN m.marketTags t WHERE m.name LIKE%:keyword% OR t.tag LIKE%:keyword% AND m.investmentSimulation IS NULL") Page findAllBackTestBySearch(@Param("keyword") String keyword, Pageable pageable); //마켓 모의 투자 검색 - @Query("SELECT DISTINCT m FROM Market m JOIN m.marketTags t WHERE M.name LIKE%:keyword% OR t.tag LIKE%:keyword% AND m.backTest IS NULL") + @Query("SELECT DISTINCT m FROM Market m JOIN m.marketTags t WHERE m.name LIKE%:keyword% OR t.tag LIKE%:keyword% AND m.backTest IS NULL") Page findAllInvestmentSimulationBySearch(@Param("keyword") String keyword, Pageable pageable); } From 4128746ed463db87a576ddcec1dcddd431c612e3 Mon Sep 17 00:00:00 2001 From: haweeee Date: Mon, 19 Aug 2024 20:38:33 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=EB=B9=A0=EC=A7=84=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../investment_simulation/entity/InvestmentSimulation.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/quantweb/springserver/domain/investment_simulation/entity/InvestmentSimulation.java b/src/main/java/com/quantweb/springserver/domain/investment_simulation/entity/InvestmentSimulation.java index 6ad0a43..2f82b9a 100644 --- a/src/main/java/com/quantweb/springserver/domain/investment_simulation/entity/InvestmentSimulation.java +++ b/src/main/java/com/quantweb/springserver/domain/investment_simulation/entity/InvestmentSimulation.java @@ -86,4 +86,8 @@ public class InvestmentSimulation extends BaseTimeEntity { @OneToOne(mappedBy = "investmentSimulation", fetch = FetchType.LAZY) private Graph graph; + + public void updateMarketShared(){ + this.marketShared = !marketShared; + } } \ No newline at end of file