Skip to content

Commit

Permalink
Feat: 회원 가입 시 계좌 저장 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BoyCho committed Sep 7, 2023
1 parent f7157db commit b073a7f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/com/ssafy/tott/account/service/AccountService.java
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()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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());
}

Expand Down

0 comments on commit b073a7f

Please sign in to comment.