Skip to content

Commit

Permalink
Fix: @ColumnDefault db단과 잘 호환되지 않아 모두 PrePersiste로 대체
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed Jun 16, 2024
1 parent 0ca8d5f commit f95e70b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/gt/genti/domain/Creator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

import java.util.List;

import org.hibernate.annotations.ColumnDefault;

import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.domain.enums.BankType;
import com.gt.genti.domain.enums.Sex;
import com.gt.genti.domain.enums.UserStatus;
import com.gt.genti.domain.enums.converter.db.BankTypeConverter;

import jakarta.persistence.Column;
Expand Down Expand Up @@ -56,11 +52,9 @@ public class Creator extends BaseTimeEntity {
BankType bankType;

@Column(name = "account_number", nullable = false)
@ColumnDefault("''")
String accountNumber;

@Column(name = "account_holder", nullable = false)
@ColumnDefault("''")
String accountHolder;

@Column(name = "completed_task_count", nullable = false)
Expand All @@ -71,9 +65,15 @@ public void prePersist() {
if (this.bankType == null) {
this.bankType = BankType.NONE;
}
if(this.workable == null){
if (this.workable == null) {
this.workable = true;
}
if (this.accountNumber == null) {
this.accountNumber = "";
}
if (this.accountHolder == null) {
this.accountHolder = "";
}
}

public Creator(User user) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/gt/genti/domain/Deposit.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.PrePersist;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -32,9 +33,16 @@ public class Deposit extends BaseTimeEntity {
User user;

@Column(name = "now_amount", nullable = false)
@ColumnDefault("0")
Long nowAmount;


@PrePersist
public void prePersist(){
if(this.nowAmount == null){
this.nowAmount = 0L;
}
}

public void add(Long amount) {
if (amount < 0) {
throw ExpectedException.withLogging(DomainErrorCode.AddPointAmountCannotBeMinus);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/gt/genti/domain/PictureGenerateResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.PrePersist;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -51,18 +52,25 @@ public class PictureGenerateResponse extends BaseTimeEntity {
PictureGenerateResponseStatus status;

@Column(name = "memo", nullable = false)
@ColumnDefault("''")
String memo;

@Column(name = "admin_in_charge", nullable = false)
@ColumnDefault("''")
String adminInCharge;

@Column(name = "submitted_by_creator_at")
LocalDateTime submittedByCreatorAt;
@Column(name = "submitted_by_admin_at")
LocalDateTime submittedByAdminAt;

@PrePersist
public void prePersist(){
if(this.memo == null){
this.memo = "";
}
if(this.adminInCharge == null){
this.adminInCharge = "";
}
}
public Duration creatorSubmitAndGetElaspedTime() {
//TODO 공급자가 제출시 불가한 상태가 있는지 생각해볼것
// edited at 2024-05-20
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/gt/genti/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class User extends BaseTimeEntity {
Sex sex;

@Column(name = "introduction", nullable = false)
@ColumnDefault("''")
String introduction;

@Column(name = "username", nullable = false)
Expand Down Expand Up @@ -106,16 +105,14 @@ public class User extends BaseTimeEntity {
LocalDateTime lastLoginDate;

@Column(name = "login", nullable = false)
@ColumnDefault("false")
Boolean login;

// user hard delete시 deposit도 삭제
@OneToOne(mappedBy = "user", cascade = CascadeType.REMOVE)
private Deposit deposit;

@Column(name = "request_task_count", nullable = false)
@ColumnDefault("0")
int requestTaskCount;
Integer requestTaskCount;

@Column(name = "birth_date")
LocalDate birthDate;
Expand All @@ -131,6 +128,13 @@ public void prePersist() {
if (this.sex == null){
this.sex = Sex.NONE;
}
if(this.introduction == null){
this.introduction = "";
}

if(this.requestTaskCount == null){
this.requestTaskCount = 0;
}
}

public static User createNewSocialUser(OAuthAttributes oauthAttributes) {
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/gt/genti/domain/WithdrawRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.PrePersist;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -33,17 +34,29 @@ public class WithdrawRequest extends BaseEntity {
Creator creator;

@Column(name = "amount", nullable = false)
@ColumnDefault("0")
long amount;
Long amount;

@Column(name = "task_count", nullable = false)
@ColumnDefault("0")
int taskCount;
Integer taskCount;

@Convert(converter = WithdrawRequestStatusConverter.class)
@Column(name = "status", nullable = false)
WithdrawRequestStatus status;


@PrePersist
public void prePersist(){
if(this.amount == null){
this.amount = 0L;
}
if(this.taskCount == null){
this.taskCount = 0;
}
if(this.status == null){
this.status = WithdrawRequestStatus.IN_PROGRESS;
}
}

public WithdrawRequest(Creator creator) {
this.creator = creator;
this.status = WithdrawRequestStatus.IN_PROGRESS;
Expand Down

0 comments on commit f95e70b

Please sign in to comment.