Skip to content

Commit ff961ef

Browse files
committed
Merge branch 'dev' of https://github.com/woorifisa-projects-3rd/Crews-BE-Core into 47-balance-info
2 parents 3379bfc + 20d1662 commit ff961ef

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

src/main/java/org/baas/baascore/controller/AccountController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public ResponseEntity<List<AccountInitResponse>> getAccountInfo(@RequestBody Mem
5656
List<AccountInitResponse> accountInfoList = accountService.findAccountInit(memberRequestDtoDto);
5757
return ResponseEntity.ok(accountInfoList);
5858
}
59+
60+
@PostMapping("/info/date")
61+
public ResponseEntity<TransactionDetailResponse> getAccountInfoOfDate(@RequestBody AccountInfoOfDate accountInfoOfDate) {
62+
return ResponseEntity.ok().body(accountService.getAccountInfoOfDate(accountInfoOfDate));
63+
}
5964
}
6065

6166

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.baas.baascore.dto.request;
2+
3+
import org.baas.baascore.util.TranType;
4+
5+
import jakarta.validation.constraints.NotBlank;
6+
import jakarta.validation.constraints.NotNull;
7+
import lombok.AllArgsConstructor;
8+
import lombok.Builder;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
12+
@Getter
13+
@NoArgsConstructor
14+
@AllArgsConstructor
15+
@Builder
16+
public class AccountInfoOfDate {
17+
18+
@NotBlank
19+
private String ci;
20+
21+
@NotBlank
22+
private String fintechUseNum;
23+
24+
@NotNull
25+
private Integer year;
26+
27+
@NotNull
28+
private Integer month;
29+
30+
@NotNull
31+
private TranType tranType;
32+
33+
}

src/main/java/org/baas/baascore/repository/TransactionHistoryRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ List<TransactionHistory> findTransactionHistorySelectedTranType(@Param("account"
2828
@Param("filteredDate") LocalDateTime filteredDate,
2929
@Param("transactionType") TranType transactionType);
3030

31+
32+
@Query("SELECT t FROM TransactionHistory t WHERE t.account =:account AND FUNCTION('YEAR', t.createdAt) = :year AND FUNCTION('MONTH', t.createdAt) = :month AND t.tranType = :transactionType ORDER BY t.createdAt DESC")
33+
List<TransactionHistory> findTransactionHistoryYearAndMonth(@Param("account") Account account,
34+
@Param("year") Integer year,
35+
@Param("month") Integer month,
36+
@Param("transactionType") TranType transactionType);
37+
3138
}

src/main/java/org/baas/baascore/service/AccountService.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class AccountService {
3434
private final CustomerRepository customerRepository;
3535
private final CardRepository cardRepository;
3636
private final ProductRepository productRepository;
37+
private final TransactionHistoryRepository transactionHistoryRepository;
38+
3739

3840
public AccountIssuedResponse accountIssued(AccountIssuedRequest accountIssuedRequest, AccountType accountTypeCrew) {
3941
Customer customer = customerRepository.findByCi(accountIssuedRequest.getCi()).orElseThrow(
@@ -155,4 +157,28 @@ public List<AccountInitResponse> findAccountInit(MemberInitRequest memberInitReq
155157
.map(AccountInitResponse::from)
156158
.toList();
157159
}
160+
161+
public TransactionDetailResponse getAccountInfoOfDate(AccountInfoOfDate accountInfoOfDate) {
162+
163+
Account account = accountRepository.findByFintechUseNum(accountInfoOfDate.getFintechUseNum()).orElseThrow(
164+
() -> new CustomException(ErrorCode.ACCOUNTNUMBER_NOT_FOUND)
165+
);
166+
Customer customer = customerRepository.findByCi(accountInfoOfDate.getCi()).orElseThrow(
167+
() -> new CustomException(ErrorCode.IDENTITYCODE_NOT_FOUND)
168+
);
169+
if (!customer.equals(account.getCustomer()) && account.getAccountType().equals(AccountType.PERSONAL)){
170+
throw new CustomException(ErrorCode.MEMBER_NOT_EQUALS);
171+
}
172+
List<TransactionHistory> list = transactionHistoryRepository.findTransactionHistoryYearAndMonth(
173+
account, accountInfoOfDate.getYear(), accountInfoOfDate.getMonth(), accountInfoOfDate.getTranType());
174+
175+
List<TransactionHistoryResponse> historyDtoList = list.stream().map(TransactionHistoryResponse::from).toList();
176+
return TransactionDetailResponse.builder().tranList(historyDtoList)
177+
.accountNumber(account.getAccountNumber())
178+
.productName(account.getProduct().getProductName())
179+
.balance(account.getBalance())
180+
.bankCode(account.getBank().getBankCode())
181+
.bankName(account.getBank().getBankName())
182+
.build();
183+
}
158184
}

0 commit comments

Comments
 (0)