domain 하위에 account, user, transaction 폴더를 만들고
각각의 엔티티를 생성해 주었다.
- USER
@NoArgsConstructor //스프링이 User 객체생성할때 빈 생성자로 new 하기 때문
@EntityListeners(AuditingEntityListener.class)
@Table(name = "user_tb")
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false, length = 20)
private String username;
@Column(nullable = false, length = 60) //패스워드 인코딩(Bcrypt)
private String password;
@Column(nullable = false, length = 20)
private String email;
@Column(nullable = false, length = 20)
private String fullname;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private UserEnum role; //ADMIN, CUSTOMER
@CreatedDate
@Column(nullable = false)
private LocalDateTime createdAt;
@LastModifiedDate
@Column(nullable = false)
private LocalDateTime updatedAt;
}this.id = id; this.username = username; this.password = password; this.email = email; this.fullname = fullname; this.role = role; this.createdAt = createdAt; this.updatedAt = updatedAt;
} - @Builder
public User(Long id, String username, String password, String email, String fullname, UserEnum role, LocalDateTime createdAt, LocalDateTime updatedAt) { - ENUMCLASS 생성
@Column(nullable = false)
private UserEnum role; //ADMIN, CUSTOMER
@Getter
@AllArgsConstructor
public enum UserEnum {
ADMIN("관리자"), CUSTOMER("고객");
private String value;
}
- Account 생성
@NoArgsConstructor
@EntityListeners(AuditingEntityListener.class)
@Table(name = "account_tb")
@Entity
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false, length = 4)
private Long number;
@Column(nullable = false, length = 4)
private Long password;
@Column(nullable = false)
private Long balance;@CreatedDate
@Column(nullable = false)
private LocalDateTime createdAt;
@LastModifiedDate
@Column(nullable = false)
private LocalDateTime updatedAt;
}this.id = id; this.number = number; this.password = password; this.balance = balance; this.user = user; this.createdAt = createdAt; this.updatedAt = updatedAt;
} - @Builder
public Account(Long id, Long number, Long password, Long balance, User user, LocalDateTime createdAt, LocalDateTime updatedAt) { - @ManyToOne(fetch = FetchType.LAZY) //account.getUser().아무필드() === 호출됨
private User user;
- Transaction 생성
@NoArgsConstructor
@EntityListeners(AuditingEntityListener.class)
@Table(name = "transactioin_tb")
@Entity
public class Transaction {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ManyToOne(fetch = FetchType.LAZY)
private Account depositAccount;@Enumerated(EnumType.STRING)
@Column(nullable = false)
private TransactionEnum gubun; //WITHDRAW, DEPOSIT, TRANSFER, ALL@CreatedDate
@Column(nullable = false)
private LocalDateTime createdAt;
@LastModifiedDate
@Column(nullable = false)
private LocalDateTime updatedAt;
}this.id = id; this.withdrawAccount = withdrawAccount; this.depositAccount = depositAccount; this.amount = amount; this.withdrawAccountBalance = withdrawAccountBalance; this.depositAccountBalance = depositAccountBalance; this.gubun = gubun; this.sender = sender; this.receiver = receiver; this.tel = tel; this.createdAt = createdAt; this.updatedAt = updatedAt;
} - public Transaction(Long id, Account withdrawAccount, Account depositAccount, Long amount, Long withdrawAccountBalance, Long depositAccountBalance, TransactionEnum gubun, String sender, String receiver, String tel, LocalDateTime createdAt, LocalDateTime updatedAt) {
- //계좌가 사라져도 로그는 남아야 함
private String sender;
private String receiver;
private String tel; - private Long amount;
private Long withdrawAccountBalance;
private Long depositAccountBalance; - @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ManyToOne(fetch = FetchType.LAZY)
private Account withdrawAccount;
여기에도 있는 ENUM
@AllArgsConstructor
@Getter
public enum TransactionEnum {
WITHDRAW("출금"), DEPOSIT("입금"), TRANSFER("이체"), ALL("입출금내역");
private String value;
}
'Bank Application' 카테고리의 다른 글
[Bank Application] 2-1. Security Config (1) | 2024.09.26 |
---|---|
git repository 연결 후 push (0) | 2024.09.26 |
[Bank Application] 1-3. 테이블 설계 (0) | 2024.09.26 |
[Bank Application] 1-2. 화면설계 (0) | 2024.09.25 |
[Bank Application] 1-1. 프로젝트 생성 (2) | 2024.09.25 |