diff --git a/src/main/java/com/sopt/solsol/service/TransferService.java b/src/main/java/com/sopt/solsol/service/TransferService.java index 17558c8..482e38f 100644 --- a/src/main/java/com/sopt/solsol/service/TransferService.java +++ b/src/main/java/com/sopt/solsol/service/TransferService.java @@ -15,6 +15,7 @@ import javax.persistence.EntityNotFoundException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -71,20 +72,30 @@ public void delete(Long transferId, Long memberId ) { @Transactional(readOnly = true) public List getTransferList(Long memberId) { - return transferRepository.findAllByMemberIdOrderByCreatedAtDesc(memberId) - .stream() - .map(transfer -> TransferResponseDTO.builder() - .id(transfer.getId()) - .accountsId(transfer.getAccounts().getId()) - .accountNumber(transfer.getAccounts().getNumber()) - .bank(transfer.getAccounts().getBank().toString()) - .name(transfer.getAccounts().getMember().getName()) - .price(transfer.getPrice()) - .createdAt(changeFormat(transfer.getCreatedAt())) - .build()) - .collect(Collectors.toList()); + List accountNumberList = new ArrayList<>(); + List transferList = transferRepository.findAllByMemberIdOrderByCreatedAtDesc(memberId); + + List transferResponseDTOList = new ArrayList<>(); + for (Transfer transfer: transferList) { + if( accountNumberList.contains(transfer.getAccounts().getId())) { + continue; + } else { + transferResponseDTOList.add( + TransferResponseDTO.builder() + .id(transfer.getId()) + .accountsId(transfer.getAccounts().getId()) + .accountNumber(transfer.getAccounts().getNumber()) + .bank(transfer.getAccounts().getBank().toString()) + .name(transfer.getAccounts().getMember().getName()) + .price(transfer.getPrice()) + .createdAt(changeFormat(transfer.getCreatedAt())) + .build() + ); + accountNumberList.add(transfer.getAccounts().getId()); + } + } + return transferResponseDTOList; } - private String changeFormat(LocalDateTime localDateTime) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd"); return localDateTime.format(formatter).toString();