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

[FIX] Account 투자 계좌 조회, 내 계좌 정보 조회 수정 #81

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ public ResponseEntity<SuccessResponse<AccountCreateResponse>> createAccount(
@GetMapping("/inquire")
public ResponseEntity<SuccessResponse<AccountResponse>> inquireAccount(
@AuthenticationPrincipal MemberPrincipal memberPrincipal) throws JsonProcessingException {

AccountResponse response = accountService.inquireAccount(memberPrincipal.getMemberId(), memberPrincipal.getUserKey());
return ResponseEntity.ok(SuccessResponse.ok(response));
}

@PatchMapping("/update-color")
public ResponseEntity<SuccessResponse<AccountResponse>> updateCustomColor(
@RequestParam String accountNumber,
@AuthenticationPrincipal MemberPrincipal memberPrincipal,
@RequestBody ColorUpdateRequest request) {
AccountResponse response = accountService.updateAccountColor(accountNumber, request.getNewColor());
AccountResponse response = accountService.updateAccountColor(memberPrincipal.getMemberId(), request.getNewColor());
return ResponseEntity.ok(SuccessResponse.ok(response));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import java.util.Optional;

public interface AccountRepository extends JpaRepository<Account, Long> {
Optional<Account> findByAccountNumber(String bankbookNumber);
Optional<Account> findByMemberMemberId(Long memberId);

// memberId로 Bankbook 조회
// memberId로 Account 조회
@Query("SELECT b FROM Account b WHERE b.member.memberId = :memberId")
Optional<Account> findByMemberId(@Param("memberId")Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public AccountCreateResponse createAccount(AccountRequest request, String userKe
// 계좌 조회 메서드
public AccountResponse inquireAccount(Long memberId, String userKey) throws JsonProcessingException {
// 1. 계좌번호 가져오기
Optional<Account> optionalAccount = accountRepository.findByMemberMemberId(memberId);
Optional<Account> optionalAccount = accountRepository.findByMemberId(memberId);

if (!optionalAccount.isPresent()) {
throw new RuntimeException("해당 회원의 계좌를 찾을 수 없습니다.");
Expand All @@ -95,8 +95,9 @@ public AccountResponse inquireAccount(Long memberId, String userKey) throws Json
}

// 커스텀 색상 업데이트
public AccountResponse updateAccountColor(String accountNumber, String newColor) {
Optional<Account> optionalAccount = accountRepository.findByAccountNumber(accountNumber);
public AccountResponse updateAccountColor(Long memberId, String newColor) {

Optional<Account> optionalAccount = accountRepository.findByMemberId(memberId);

if (!optionalAccount.isPresent()) {
throw new RuntimeException("해당 계좌 번호를 가진 계좌를 찾을 수 없습니다.");
Expand Down Expand Up @@ -176,6 +177,7 @@ private Map<String, Object> callInquireAccountApi(String accountNo, String userK
header.put("institutionCode", "00100");
header.put("fintechAppNo", "001");
header.put("apiServiceCode", "inquireDemandDepositAccount");
header.put("institutionTransactionUniqueNo", TransactionUtil.generateUniqueTransactionNo());
header.put("apiKey", apiKey);
header.put("userKey", userKey);

Expand Down Expand Up @@ -284,7 +286,7 @@ private AccountHistoryResponse mapAccountHistory(Map<String, Object> accountData
// 계좌 정보 조회 메서드
public AccountInfoResponse getAccountInfo(Long memberId, String userKey) throws JsonProcessingException {
// 1. 계좌번호 가져오기
Optional<Account> optionalAccount = accountRepository.findByMemberMemberId(memberId);
Optional<Account> optionalAccount = accountRepository.findByMemberId(memberId);

if (!optionalAccount.isPresent()) {
throw new RuntimeException("해당 회원의 계좌를 찾을 수 없습니다.");
Expand All @@ -299,7 +301,7 @@ public AccountInfoResponse getAccountInfo(Long memberId, String userKey) throws
String accountCode = (String) responseMap.get("accountCode");

// 3. 계좌 코드와 매핑된 계좌 이름 가져오기
Optional<AccountCode> optionalAccountCode = accountCodeRepository.findByAccountCode(accountCode); // 메서드 이름 변경에 따라 수정
Optional<AccountCode> optionalAccountCode = accountCodeRepository.findByAccountCode(accountCode);

if (!optionalAccountCode.isPresent()) {
throw new RuntimeException("해당 계좌 코드를 찾을 수 없습니다.");
Expand Down Expand Up @@ -329,7 +331,7 @@ private Map<String, Object> callInquireAccountBalanceApi(String accountNo, Strin
header.put("institutionCode", "00100");
header.put("fintechAppNo", "001");
header.put("apiServiceCode", "inquireDemandDepositAccountBalance");
header.put("institutionTransactionUniqueNo", now.format(dateFormatter) + now.format(timeFormatter) + userKey);
header.put("institutionTransactionUniqueNo", TransactionUtil.generateUniqueTransactionNo());
header.put("apiKey", apiKey);
header.put("userKey", userKey);

Expand Down
Loading