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

[FEAT] 랜덤 이름 생성 API 구현 #140

Merged
merged 4 commits into from
Aug 31, 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 @@ -17,6 +17,7 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
Expand Down Expand Up @@ -84,4 +85,11 @@ public ResponseEntity<SuccessResponse<AccountCreateColorResponse>> creatAccountC
AccountCreateColorResponse response = accountService.createColorAccount(request, memberPrincipal.getMemberId());
return ResponseEntity.ok(SuccessResponse.ok(response));
}

@GetMapping("/name")
public SuccessResponse<?> getRandomName(){
HashMap<String, String> name = accountService.getRandomName();

return SuccessResponse.ok(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,34 @@ public class AccountService {
@Value("${api.key}")
private String apiKey;

private final List<String> names = Arrays.asList(
"김민준", "이서준", "박지훈", "최성민", "정우진",
"강현우", "조준호", "임태현", "오진우", "윤경민",
"허시우", "송유진", "문재현", "장도현", "이기찬",
"김남준", "김주원", "박원빈", "김한결", "오병호",
"이승현", "김서연", "이지민", "박수빈", "최유진",
"정예린", "강은지", "조수아", "임하늘", "오지아",
"윤나연", "허민지", "송경희", "문진아", "장현정",
"이소희", "김가연", "김유나", "박소연", "최세진",
"김하은", "유서하"
);
private final Random random = new Random();
private final List<String> categories = initializeCategories();

public HashMap<String, String> getRandomName() {
int index = random.nextInt(names.size());
HashMap<String, String> data = new HashMap<>();
data.put("name", names.get(index));
return data;
}


private List<String> initializeCategories() {
List<String> categoryList = new ArrayList<>();
for (int i = 0; i < 4; i++) categoryList.add("식비");
for (int i = 0; i < 3; i++) categoryList.add("식비");
for (int i = 0; i < 2; i++) categoryList.add("교통");
for (int i = 0; i < 3; i++) categoryList.add("쇼핑");
for (int i = 0; i < 2; i++) categoryList.add("쇼핑");
for (int i = 0; i < 1; i++) categoryList.add("반려");
categoryList.add("기타");
return categoryList;
}
Expand Down Expand Up @@ -179,11 +200,11 @@ public void transferMoney(MemberPrincipal memberPrincipal, TransferRequest trans
String transferNo = callTransferMoney(member.getDepositAccount(), memberPrincipal.getUserKey(), transferRequest);
// 2. 메모하기
log.info("transferNo: {}", transferNo);
transactionService.makeMemo(member.getDepositAccount(), transferNo, setMemoCategory(), memberPrincipal.getUserKey());
String memo = transferRequest.getName() + "," + setMemoCategory();
transactionService.makeMemo(member.getDepositAccount(), transferNo, memo, memberPrincipal.getUserKey());
}

private String setMemoCategory(){
Random random = new Random();
int index = random.nextInt(categories.size());
return categories.get(index);
}
Expand All @@ -196,7 +217,7 @@ private String callTransferMoney(String accountNo, String userKey, TransferReque
body.put("Header", header);
body.put("accountNo", accountNo);
body.put("transactionBalance", transferRequest.getAmount());
body.put("transferSummary", "출금");
body.put("transactionSummary", "출금");

// 2. HttpHeaders 설정
HttpHeaders headers = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public class TransferRequest {
private String account;
@NotNull
private Long amount;
@NotBlank
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ private void extractTransactionDetails(String accountNo, String userKey, Transac

// 각 거래 항목의 세부 정보를 리스트에 추가
for (Map<String, Object> transaction : transactionList) {
String name = ((String) transaction.get("transactionMemo")).split(",")[0];

TransactionDetailResponse detail = TransactionDetailResponse.builder()
.transactionUniqueNo(Long.valueOf((String) transaction.get("transactionUniqueNo")))
.transactionDate((String) transaction.get("transactionDate"))
.transactionTime((String) transaction.get("transactionTime"))
.transactionBalance(Long.valueOf(transaction.get("transactionBalance").toString()))
.transactionAfterBalance(Long.valueOf(transaction.get("transactionAfterBalance").toString()))
.transactionSummary((String) transaction.get("transactionSummary"))
.transactionMemo((String) transaction.get("transactionMemo"))
.transactionMemo(name)
.build();
transactionDetails.add(detail);
}
Expand Down
Loading