Replies: 2 comments 1 reply
-
저는
|
Beta Was this translation helpful? Give feedback.
1 reply
-
결론 : 현재는 PayAccountHistory -> PayAccount 방향의 단방향 매핑을 추가해서 PayAccount에서 아래와 같이 History 로그를 쉽게 관리하도록함. @Entity
@Slf4j
public class PayAccount {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "balance", nullable = false)
@ColumnDefault("0")
private long balance;
@OneToMany(mappedBy = "payAccount", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private List<PayAccountHistory> history = new ArrayList<>();
public PayAccount() {
this.balance = 0;
}
public Long getId() {
return id;
}
public long getBalance() {
return this.balance;
}
//domain method 실행과 함께 History를 저장할 수 있습니다.
public PayAccountHistory charge(long amount) {
validateTransactionAmount(amount);
validateDailyChargeLimit(amount);
this.balance += amount;
return issueAndSavePayAccountHistory(amount, AccountTransactionType.CHARGE);
}
private PayAccountHistory issueAndSavePayAccountHistory(long amount, AccountTransactionType type) {
PayAccountHistory payAccountHistory = new PayAccountHistory(this, amount, type);
this.history.add(payAccountHistory);
return payAccountHistory;
}
...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Link
이슈 #3 에서 파생된 문제입니다.
문제 정의
일일 한도는 100만원이다
라는 요구사항은 PayAccount에서 확인하는 책임까지 있다고 생각합니다.Beta Was this translation helpful? Give feedback.
All reactions