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/#75] 계정 조회 API 차대변 분리 #76

Merged
merged 1 commit into from
Feb 1, 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 @@ -2,7 +2,11 @@

import static com.friends.easybud.transaction.dto.TransactionResponse.TransactionDto;

import com.friends.easybud.global.exception.GeneralException;
import com.friends.easybud.global.response.code.ErrorStatus;
import com.friends.easybud.transaction.domain.Account;
import com.friends.easybud.transaction.domain.AccountState;
import com.friends.easybud.transaction.domain.AccountType;
import com.friends.easybud.transaction.domain.Transaction;
import com.friends.easybud.transaction.dto.TransactionResponse.AccountDto;
import com.friends.easybud.transaction.dto.TransactionResponse.TransactionListDto;
Expand All @@ -19,7 +23,13 @@ public static TransactionListDto toTransactionListDto(List<Transaction> transact
}

public static TransactionDto toTransactionDto(Transaction transaction) {
List<AccountDto> accountDtos = transaction.getAccounts().stream()
List<AccountDto> debitAccounts = transaction.getAccounts().stream()
.filter(account -> isDebitAccount(account.getAccountType())) // 차변 계정인지 확인
.map(TransactionConverter::toAccountDto)
.collect(Collectors.toList());

List<AccountDto> creditAccounts = transaction.getAccounts().stream()
.filter(account -> !isDebitAccount(account.getAccountType())) // 대변 계정인지 확인
.map(TransactionConverter::toAccountDto)
.collect(Collectors.toList());

Expand All @@ -28,7 +38,8 @@ public static TransactionDto toTransactionDto(Transaction transaction) {
.date(transaction.getDate())
.summary(transaction.getSummary())
.type(transaction.getType())
.accounts(accountDtos)
.debitAccounts(debitAccounts)
.creditAccounts(creditAccounts)
.build();
}

Expand All @@ -46,4 +57,21 @@ public static AccountDto toAccountDto(Account account) {
.amount(account.getAmount()).build();
}

private static boolean isDebitAccount(AccountType accountType) {
switch (accountType.getTypeName()) {
case ASSET:
return accountType.getTypeState() == AccountState.INCREASE;
case LIABILITY:
case EQUITY:
return accountType.getTypeState() == AccountState.DECREASE;
case EXPENSE:
return accountType.getTypeState() == AccountState.OCCURRENCE;
case REVENUE:
return false; // 수익은 항상 대변
default:
throw new GeneralException(ErrorStatus.ACCOUNT_NOT_FOUND);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public static class TransactionDto {
@Schema(description = "거래 유형", example = "EXPENSE_TRANSACTION")
private TransactionType type;

@ArraySchema(schema = @Schema(description = "계정 목록", implementation = AccountDto.class))
private List<AccountDto> accounts;
@ArraySchema(schema = @Schema(description = "차변 계정 목록", implementation = AccountDto.class))
private List<AccountDto> debitAccounts;

@ArraySchema(schema = @Schema(description = "대변 계정 목록", implementation = AccountDto.class))
private List<AccountDto> creditAccounts;

}

Expand Down
Loading