From e196b5e7fb8852130264296b2fdbed222537f27f Mon Sep 17 00:00:00 2001 From: ahnsugyeong Date: Wed, 14 Feb 2024 02:25:27 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[Feat/#112]=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=20=ED=86=A0=ED=81=B0=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/friends/easybud/global/config/SwaggerConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/friends/easybud/global/config/SwaggerConfig.java b/src/main/java/com/friends/easybud/global/config/SwaggerConfig.java index a194bfe..a3890a1 100644 --- a/src/main/java/com/friends/easybud/global/config/SwaggerConfig.java +++ b/src/main/java/com/friends/easybud/global/config/SwaggerConfig.java @@ -42,7 +42,7 @@ public OpenAPI openAPI() { --- ### πŸ”‘ ν…ŒμŠ€νŠΈ μ‚¬μš©μž 인증 토큰 - **eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzYjk5ZjYwZC1mOWY1LTQ2MmUtODg5NS0yM2E1MmVkZDI0NTEiLCJhdXRoIjoiVVNFUiIsImV4cCI6MTcwNzc4OTE2MX0.hrEnXsmipLqpWSv9pw4GHHo3LfIo_yFVM7Ojg9DwN6I** + **eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzYjk5ZjYwZC1mOWY1LTQ2MmUtODg5NS0yM2E1MmVkZDI0NTEiLCJhdXRoIjoiVVNFUiIsImV4cCI6MTcwNzg0NjgxOX0.ovjnSjn0Dmm1d8AYTlL4Fklh5KhHEDNpmW-3zr3ZRks** """); From df928ea5d46949cf1a538cece3a8769dc98eaa0a Mon Sep 17 00:00:00 2001 From: ahnsugyeong Date: Wed, 14 Feb 2024 02:49:36 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[Feat/#112]=20=EA=B1=B0=EB=9E=98=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=EC=97=90=20=EA=B1=B0=EB=9E=98=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/TransactionConverter.java | 1 + .../transaction/domain/Transaction.java | 8 ++++- .../transaction/domain/TransactionType.java | 5 +++ .../transaction/dto/TransactionResponse.java | 4 +++ .../TransactionCommandServiceImpl.java | 35 +++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/friends/easybud/transaction/domain/TransactionType.java diff --git a/src/main/java/com/friends/easybud/transaction/converter/TransactionConverter.java b/src/main/java/com/friends/easybud/transaction/converter/TransactionConverter.java index de69e4d..5af8383 100644 --- a/src/main/java/com/friends/easybud/transaction/converter/TransactionConverter.java +++ b/src/main/java/com/friends/easybud/transaction/converter/TransactionConverter.java @@ -37,6 +37,7 @@ public static TransactionDto toTransactionDto(Transaction transaction) { .transactionId(transaction.getId()) .date(transaction.getDate()) .summary(transaction.getSummary()) + .type(transaction.getType()) .debitAccounts(debitAccounts) .creditAccounts(creditAccounts) .build(); diff --git a/src/main/java/com/friends/easybud/transaction/domain/Transaction.java b/src/main/java/com/friends/easybud/transaction/domain/Transaction.java index 4b434ec..efc6631 100644 --- a/src/main/java/com/friends/easybud/transaction/domain/Transaction.java +++ b/src/main/java/com/friends/easybud/transaction/domain/Transaction.java @@ -4,6 +4,8 @@ import com.friends.easybud.member.domain.Member; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -31,6 +33,9 @@ public class Transaction extends BaseTimeEntity { private LocalDateTime date; private String summary; + @Enumerated(value = EnumType.STRING) + private TransactionType type; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; @@ -39,9 +44,10 @@ public class Transaction extends BaseTimeEntity { private List accounts = new ArrayList<>(); @Builder - public Transaction(LocalDateTime date, String summary, Member member) { + public Transaction(LocalDateTime date, String summary, TransactionType type, Member member) { this.date = date; this.summary = summary; + this.type = type; this.member = member; } } diff --git a/src/main/java/com/friends/easybud/transaction/domain/TransactionType.java b/src/main/java/com/friends/easybud/transaction/domain/TransactionType.java new file mode 100644 index 0000000..e73e05d --- /dev/null +++ b/src/main/java/com/friends/easybud/transaction/domain/TransactionType.java @@ -0,0 +1,5 @@ +package com.friends.easybud.transaction.domain; + +public enum TransactionType { + EXPENSE_TRANSACTION, REVENUE_TRANSACTION, ACCOUNT_TRANSFER +} diff --git a/src/main/java/com/friends/easybud/transaction/dto/TransactionResponse.java b/src/main/java/com/friends/easybud/transaction/dto/TransactionResponse.java index 0cf46a5..eff5c56 100644 --- a/src/main/java/com/friends/easybud/transaction/dto/TransactionResponse.java +++ b/src/main/java/com/friends/easybud/transaction/dto/TransactionResponse.java @@ -1,6 +1,7 @@ package com.friends.easybud.transaction.dto; import com.friends.easybud.transaction.domain.AccountType; +import com.friends.easybud.transaction.domain.TransactionType; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Schema; import java.math.BigDecimal; @@ -47,6 +48,9 @@ public static class TransactionDto { @Schema(description = "μ μš”", example = "μŠ€νƒ€λ²…μŠ€") private String summary; + @Schema(description = "거래 μœ ν˜•", example = "EXPENSE_TRANSACTION") + private TransactionType type; + @ArraySchema(schema = @Schema(description = "μ°¨λ³€ 계정 λͺ©λ‘", implementation = AccountDto.class)) private List debitAccounts; diff --git a/src/main/java/com/friends/easybud/transaction/service/TransactionCommandServiceImpl.java b/src/main/java/com/friends/easybud/transaction/service/TransactionCommandServiceImpl.java index 84b7eff..c8732d2 100644 --- a/src/main/java/com/friends/easybud/transaction/service/TransactionCommandServiceImpl.java +++ b/src/main/java/com/friends/easybud/transaction/service/TransactionCommandServiceImpl.java @@ -8,11 +8,15 @@ import com.friends.easybud.global.response.code.ErrorStatus; import com.friends.easybud.member.domain.Member; import com.friends.easybud.transaction.domain.Account; +import com.friends.easybud.transaction.domain.AccountName; +import com.friends.easybud.transaction.domain.AccountState; import com.friends.easybud.transaction.domain.Transaction; +import com.friends.easybud.transaction.domain.TransactionType; import com.friends.easybud.transaction.dto.TransactionRequest.AccountCreateDto; import com.friends.easybud.transaction.dto.TransactionRequest.TransactionCreateDto; import com.friends.easybud.transaction.repository.AccountRepository; import com.friends.easybud.transaction.repository.TransactionRepository; +import java.math.BigDecimal; import java.time.Duration; import java.time.LocalDateTime; import java.util.List; @@ -47,6 +51,7 @@ private Transaction buildTransaction(TransactionCreateDto request, Member member Transaction transaction = Transaction.builder() .date(request.getDate()) .summary(request.getSummary()) + .type(getTransactionType(request.getAccounts())) .member(member) .build(); return transaction; @@ -116,4 +121,34 @@ private void checkTransactionOwnership(Member member, Transaction transaction) { } } + private TransactionType getTransactionType(List accounts) { + BigDecimal totalExpenses = BigDecimal.ZERO; + BigDecimal totalRevenues = BigDecimal.ZERO; + + for (AccountCreateDto account : accounts) { + if (account.getAccountType().getTypeName() == AccountName.EXPENSE) { + if (account.getAccountType().getTypeState() == AccountState.INCREASE) { + totalExpenses = totalExpenses.add(account.getAmount()); + } else if (account.getAccountType().getTypeState() == AccountState.DECREASE) { + totalExpenses = totalExpenses.subtract(account.getAmount()); + } + + } else if (account.getAccountType().getTypeName() == AccountName.REVENUE) { + if (account.getAccountType().getTypeState() == AccountState.INCREASE) { + totalRevenues = totalRevenues.add(account.getAmount()); + } else if (account.getAccountType().getTypeState() == AccountState.DECREASE) { + totalRevenues = totalRevenues.subtract(account.getAmount()); + } + } + } + + if (totalExpenses.compareTo(totalRevenues) > 0) { + return TransactionType.EXPENSE_TRANSACTION; + } else if (totalRevenues.compareTo(totalExpenses) > 0) { + return TransactionType.REVENUE_TRANSACTION; + } else { + return TransactionType.ACCOUNT_TRANSFER; + } + } + } From 902609b667dcb922806434099821bce6e6b077e6 Mon Sep 17 00:00:00 2001 From: ahnsugyeong Date: Wed, 14 Feb 2024 03:03:57 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[Feat/#112]=20=EC=88=9C=EC=9E=90=EC=82=B0?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20memberId=20=EB=B9=84=EA=B5=90=EB=AC=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../transaction/repository/AccountCustomRepositoryImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/friends/easybud/transaction/repository/AccountCustomRepositoryImpl.java b/src/main/java/com/friends/easybud/transaction/repository/AccountCustomRepositoryImpl.java index a50f3f2..417e85c 100644 --- a/src/main/java/com/friends/easybud/transaction/repository/AccountCustomRepositoryImpl.java +++ b/src/main/java/com/friends/easybud/transaction/repository/AccountCustomRepositoryImpl.java @@ -130,7 +130,8 @@ public List getAccountInfosByAccountNameAndMember(AccountName accou account.accountType.typeState) .from(account) .join(account.transaction, transaction) - .where(account.accountType.typeName.eq(accountName)) + .where(account.accountType.typeName.eq(accountName), + transaction.member.id.eq(memberId)) .fetch(); return results.stream().map(tuple -> { From 24fc2b58d20cad3a42dd40cc923f76ff6d83bae0 Mon Sep 17 00:00:00 2001 From: ahnsugyeong Date: Wed, 14 Feb 2024 03:17:16 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[Feat/#112]=20=EC=86=90=EC=9D=B5=ED=98=84?= =?UTF-8?q?=ED=99=A9=20=EB=B9=84=EC=9C=A8=20=EA=B3=84=EC=82=B0=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easybud/financial/service/FinancialServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/friends/easybud/financial/service/FinancialServiceImpl.java b/src/main/java/com/friends/easybud/financial/service/FinancialServiceImpl.java index df524ec..8f5dff0 100644 --- a/src/main/java/com/friends/easybud/financial/service/FinancialServiceImpl.java +++ b/src/main/java/com/friends/easybud/financial/service/FinancialServiceImpl.java @@ -157,6 +157,10 @@ public IncomeStatementDto getIncomeStatement(Member member, LocalDateTime startD .multiply(new BigDecimal(100)); revenuePercentage = revenue.divide(revenue.add(expense), 4, RoundingMode.HALF_UP) .multiply(new BigDecimal(100)); + } else if (expense.compareTo(BigDecimal.ZERO) == 0 && revenue.compareTo(BigDecimal.ZERO) > 0) { + revenuePercentage = BigDecimal.valueOf(100); + } else if (revenue.compareTo(BigDecimal.ZERO) == 0 && expense.compareTo(BigDecimal.ZERO) > 0) { + expensePercentage = BigDecimal.valueOf(100); } return IncomeStatementDto.builder()