-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] : 거래 장부를 위한 CoinTransaction 및 CoinTransactionEntity 엔티티 구현 #272
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
Merged
yooooonshine
merged 6 commits into
develop
from
feature/268-implement-transaction-and-entity
Nov 23, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08525e1
feat: Account에 version 추가
yooooonshine a9c1126
feat: coinTransaction 엔티티 구현
yooooonshine ffa5fb6
feat: coinTransactionEntity 엔티티 구현
yooooonshine 2e4259d
fix: status 변경하려는 오류 수정
yooooonshine b17ade3
refactor: CoinTransactionEntity 팩터리 메서드에 null 검사 추가
yooooonshine 9b6a6ef
chore: 주석 개선
yooooonshine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/hanium/modic/backend/domain/transaction/entity/CoinTransaction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package hanium.modic.backend.domain.transaction.entity; | ||
|
|
||
| import static jakarta.persistence.EnumType.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import hanium.modic.backend.common.entity.BaseEntity; | ||
| import hanium.modic.backend.domain.transaction.enums.TransactionStatus; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Transaction 거래의 단위 거래(debit, credit) | ||
| */ | ||
| @Table(name = "coin_transactions") | ||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class CoinTransaction extends BaseEntity { | ||
|
|
||
| @Id | ||
| @Column(name = "id", updatable = false) | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "status", nullable = false, updatable = false) | ||
| @Enumerated(STRING) | ||
| private TransactionStatus status; | ||
|
|
||
| @Column(name = "effective_at", nullable = true) | ||
| private LocalDateTime effectiveAt; // 거래가 실제로 반영된 시간 | ||
|
|
||
| @Builder | ||
| private CoinTransaction( | ||
| TransactionStatus status, | ||
| LocalDateTime effectiveAt | ||
| ) { | ||
| this.status = status; | ||
| this.effectiveAt = effectiveAt; | ||
| } | ||
| } |
143 changes: 143 additions & 0 deletions
143
src/main/java/hanium/modic/backend/domain/transaction/entity/CoinTransactionEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package hanium.modic.backend.domain.transaction.entity; | ||
|
|
||
| import static hanium.modic.backend.common.error.ErrorCode.*; | ||
| import static jakarta.persistence.EnumType.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import hanium.modic.backend.common.entity.BaseEntity; | ||
| import hanium.modic.backend.common.error.exception.AppException; | ||
| import hanium.modic.backend.domain.transaction.enums.TransactionDirection; | ||
| import hanium.modic.backend.domain.transaction.enums.TransactionStatus; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Transaction 거래의 단위 거래(debit, credit) | ||
| */ | ||
| @Table(name = "coin_tranaction_entities") | ||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class CoinTransactionEntity extends BaseEntity { | ||
|
|
||
| @Id | ||
| @Column(name = "id", updatable = false) | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "account_id", nullable = false, updatable = false) | ||
| private Long accountId; | ||
|
|
||
| @Column(name = "account_version", nullable = false, updatable = false) | ||
| private Long accountVersion; | ||
|
|
||
| @Column(name = "coin_transaction_id", nullable = false, updatable = false) | ||
| private Long coinTransactionId; | ||
|
|
||
| @Column(name = "status", nullable = false, updatable = false) | ||
| @Enumerated(STRING) | ||
| private TransactionStatus status; | ||
|
|
||
| @Column(name = "direction", nullable = false, updatable = false) | ||
| @Enumerated(STRING) | ||
| private TransactionDirection direction; | ||
|
|
||
| @Column(name = "amount", nullable = false, updatable = false) | ||
| private Long amount; | ||
|
|
||
| @Column(name = "discarded_at", nullable = true) | ||
| private LocalDateTime discardedAt; // 취소되지 않았으면 null | ||
|
|
||
| @Column(name = "effective_at", nullable = true) | ||
| private LocalDateTime effectiveAt; // 거래가 실제로 반영된 시간 | ||
|
|
||
| private CoinTransactionEntity( | ||
| Long accountId, | ||
| Long accountVersion, | ||
| Long coinTransactionId, | ||
| TransactionStatus status, | ||
| TransactionDirection direction, | ||
| Long amount, | ||
| LocalDateTime discardedAt, | ||
| LocalDateTime effectiveAt | ||
| ) { | ||
| this.accountId = accountId; | ||
| this.accountVersion = accountVersion; | ||
| this.coinTransactionId = coinTransactionId; | ||
| this.status = status; | ||
| this.direction = direction; | ||
| this.amount = amount; | ||
| this.discardedAt = discardedAt; | ||
| this.effectiveAt = effectiveAt; | ||
| } | ||
|
|
||
| public static CoinTransactionEntity createPendingTransaction( | ||
| Long accountId, | ||
| Long accountVersion, | ||
| Long coinTransactionId, | ||
| TransactionDirection direction, | ||
| Long amount | ||
| ) { | ||
| return new CoinTransactionEntity( | ||
| accountId, | ||
| accountVersion, | ||
| coinTransactionId, | ||
| TransactionStatus.PENDING, | ||
| direction, | ||
| amount, | ||
| null, | ||
| null | ||
| ); | ||
| } | ||
yooooonshine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // 거래가 실제로 반영된 시간도 함께 설정 | ||
| // Posted를 생성 시에는 기존 Pending 거래의 discardedAt 설정해야 함 | ||
| public static CoinTransactionEntity createPostedTransaction( | ||
| Long accountId, | ||
| Long accountVersion, | ||
| Long coinTransactionId, | ||
| TransactionDirection direction, | ||
| Long amount, | ||
| LocalDateTime effectiveAt | ||
| ) { | ||
| // effectiveAt null 체크 | ||
| if (effectiveAt == null) { | ||
| throw new AppException(EFFECTIVE_AT_CANT_NOT_BE_NULL); | ||
| } | ||
|
|
||
| return new CoinTransactionEntity( | ||
| accountId, | ||
| accountVersion, | ||
| coinTransactionId, | ||
| TransactionStatus.POSTED, | ||
| direction, | ||
| amount, | ||
| null, | ||
| effectiveAt | ||
| ); | ||
| } | ||
|
|
||
| // 거래 취소하기 | ||
| // 별도로 취소 상태의 CoinTransactionEntity 생성해야 함 | ||
| public void discardTransaction(LocalDateTime discardedAt) { | ||
| // 이미 취소된 거래는 다시 취소할 수 없음 | ||
| if (this.discardedAt != null) { | ||
| throw new AppException(COIN_TRANSFER_FAIL_EXCEPTION); | ||
| } | ||
| // discardedAt은 null일 수 없음 | ||
| if (discardedAt == null) { | ||
| throw new AppException(EFFECTIVE_AT_CANT_NOT_BE_NULL); | ||
| } | ||
|
|
||
| this.discardedAt = discardedAt; | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/main/java/hanium/modic/backend/domain/transaction/enums/TransactionDirection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package hanium.modic.backend.domain.transaction.enums; | ||
|
|
||
| public enum TransactionDirection { | ||
| DEBIT, // 출금 | ||
| CREDIT // 입금 | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/hanium/modic/backend/domain/transaction/enums/TransactionStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package hanium.modic.backend.domain.transaction.enums; | ||
|
|
||
| public enum TransactionStatus { | ||
| PENDING, // 대기중 | ||
| POSTED, // 성공 | ||
| ARCHIVED // 취소 및 보관 | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.