From b073a7fd90d1e97c39f199eed05fff6d066e2a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=ED=98=84=EC=A1=B0?= Date: Thu, 7 Sep 2023 19:42:40 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=9A=8C=EC=9B=90=20=EA=B0=80=EC=9E=85?= =?UTF-8?q?=20=EC=8B=9C=20=EA=B3=84=EC=A2=8C=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tott/account/service/AccountService.java | 38 +++++++++++++++++++ .../tott/member/service/MemberService.java | 4 ++ 2 files changed, 42 insertions(+) diff --git a/src/main/java/com/ssafy/tott/account/service/AccountService.java b/src/main/java/com/ssafy/tott/account/service/AccountService.java index c970f99..5817de4 100644 --- a/src/main/java/com/ssafy/tott/account/service/AccountService.java +++ b/src/main/java/com/ssafy/tott/account/service/AccountService.java @@ -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 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() + ); + } + } } diff --git a/src/main/java/com/ssafy/tott/member/service/MemberService.java b/src/main/java/com/ssafy/tott/member/service/MemberService.java index 0aacc2b..5fb12ce 100644 --- a/src/main/java/com/ssafy/tott/member/service/MemberService.java +++ b/src/main/java/com/ssafy/tott/member/service/MemberService.java @@ -1,6 +1,7 @@ package com.ssafy.tott.member.service; import com.ssafy.tott.account.domain.BankCode; +import com.ssafy.tott.account.service.AccountService; import com.ssafy.tott.api.shinhan.ShinhanBankAPI; import com.ssafy.tott.api.shinhan.service.searchname.dto.response.ShinhanBankSearchNameResponse; import com.ssafy.tott.api.shinhan.service.transfer1.dto.response.ShinhanBankTransfer1Response; @@ -27,6 +28,7 @@ public class MemberService { private final MemberVerificationService memberVerificationService; private final ShinhanBankAPI shinhanBankAPI; private final MemberMapper mapper; + private final AccountService accountService; @Transactional public MemberSignupResponse signup(MemberSignupRequest request) { @@ -48,6 +50,8 @@ public MemberVerificationResponse verification(MemberVerificationRequest request ShinhanBankSearchNameResponse responseAPI = (ShinhanBankSearchNameResponse) shinhanBankAPI.fetchSearchNameAPI(bankCode, accountNumber); Member savedMember = memberRepository.save(mapper.toMember(responseAPI, memberVerificationCache)); + + accountService.searchAccounts(savedMember); return MemberVerificationResponse.from(savedMember.getId()); }