-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/com/ssafy/tott/account/service/AccountService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
package com.ssafy.tott.account.service; | ||
|
||
import com.ssafy.tott.account.domain.Account; | ||
import com.ssafy.tott.account.domain.AccountRepository; | ||
import com.ssafy.tott.account.domain.BankCode; | ||
import com.ssafy.tott.account.domain.embbeded.AccountNumber; | ||
import com.ssafy.tott.api.shinhan.ShinhanBankAPI; | ||
import com.ssafy.tott.api.shinhan.service.searchaccounts.dto.response.ShinhanBankSearchAccountsResponse; | ||
import com.ssafy.tott.api.shinhan.service.searchaccounts.dto.response.body.ShinhanBankSearchAccountsResponseAccount; | ||
import com.ssafy.tott.member.domain.Member; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Service | ||
public class AccountService { | ||
private final AccountRepository accountRepository; | ||
private final ShinhanBankAPI shinhanBankAPI; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
public void searchAccounts(Member member) { | ||
// 이름 암호화 | ||
String encodedName = passwordEncoder.encode(member.getId() + member.getName()); | ||
|
||
ShinhanBankSearchAccountsResponse response = (ShinhanBankSearchAccountsResponse) shinhanBankAPI.fetchSearchAccountsAPI(encodedName); | ||
List<ShinhanBankSearchAccountsResponseAccount> responseAccounts = response.getShinhanBankSearchAccountsResponseDataBody().getAccounts(); | ||
for (ShinhanBankSearchAccountsResponseAccount responseAccount : responseAccounts) { | ||
accountRepository.save(Account.builder() | ||
.accountNumber(AccountNumber.from(responseAccount.getAccountNumber())) | ||
.amount(Long.parseLong(responseAccount.getAmount())) | ||
.member(member) | ||
.bankCode(BankCode.SHINHAN) | ||
.build() | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters