Skip to content

Commit

Permalink
refactor: 컬럼 제약조건 및 DB 동기화를 위한 엔티티 클래스 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanjaemo committed Dec 15, 2024
1 parent d88c89f commit a56a4d2
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class GameBookmark extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/balancetalk/bookmark/domain/TalkPickBookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import balancetalk.talkpick.domain.TalkPick;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class TalkPickBookmark extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down Expand Up @@ -44,5 +54,4 @@ public void activate() {
public void deactivate() {
this.active = false;
}

}
44 changes: 21 additions & 23 deletions src/main/java/balancetalk/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@
import balancetalk.member.domain.Member;
import balancetalk.talkpick.domain.TalkPick;
import balancetalk.talkpick.domain.ViewStatus;
import jakarta.persistence.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Transient;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.springframework.lang.Nullable;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Builder
Expand All @@ -23,8 +37,6 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Comment extends BaseTimeEntity {

private static final int MIN_COUNT_FOR_BLIND = 5;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -34,12 +46,11 @@ public class Comment extends BaseTimeEntity {
private String content;

@Enumerated(value = EnumType.STRING)
@NotNull
private ViewStatus viewStatus;

private Boolean isBest;

@NotNull
private int reportedCount;
private Boolean isBest;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
Expand All @@ -49,7 +60,6 @@ public class Comment extends BaseTimeEntity {
@JoinColumn(name = "talk_pick_id")
private TalkPick talkPick;

@Nullable
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private Comment parent;
Expand All @@ -60,6 +70,7 @@ public class Comment extends BaseTimeEntity {
@Transient
private Boolean isNotifiedForFirstReply = false;

@NotNull
private LocalDateTime editedAt;

private boolean isEdited;
Expand All @@ -77,19 +88,6 @@ public void setIsBest(boolean isBest) {
this.isBest = isBest;
}

public boolean isBlind() {
return this.viewStatus.equals(ViewStatus.BLIND);
}

public void incrementReportCount() {
this.reportedCount++;

if (this.reportedCount == MIN_COUNT_FOR_BLIND) {
this.content = "신고된 댓글입니다.";
this.viewStatus = ViewStatus.BLIND;
}
}

public void setIsNotifiedForFirstReplyTrue() {
this.isNotifiedForFirstReply = true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/balancetalk/file/domain/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -32,12 +33,15 @@ public class File extends BaseTimeEntity {
private Long resourceId;

@Enumerated(value = EnumType.STRING)
@NotNull
private FileType fileType;

@NotBlank
@Size(max = 50)
private String uploadName;

@NotBlank
@Size(max = 100)
private String storedName;

@NotBlank
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/balancetalk/game/domain/GameOption.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package balancetalk.game.domain;

import balancetalk.global.common.BaseTimeEntity;
import balancetalk.vote.domain.GameVote;
import balancetalk.vote.domain.VoteOption;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -30,7 +31,7 @@
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class GameOption {
public class GameOption extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/balancetalk/like/domain/Like.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Builder
Expand All @@ -19,6 +32,7 @@ public class Like extends BaseTimeEntity {
private Long id;

@Enumerated(value = EnumType.STRING)
@NotNull
private LikeType likeType;

@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -28,6 +42,7 @@ public class Like extends BaseTimeEntity {
@NotNull
private Long resourceId;

@NotNull
private Boolean active = true;

public void activate() {
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/balancetalk/talkpick/domain/TalkPick.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@
import balancetalk.member.domain.Member;
import balancetalk.vote.domain.TalkPickVote;
import balancetalk.vote.domain.VoteOption;
import jakarta.persistence.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.PositiveOrZero;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

@Entity
@Getter
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/balancetalk/talkpick/domain/TempTalkPick.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package balancetalk.talkpick.domain;

import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.validation.constraints.Size;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class TempTalkPick {
public class TempTalkPick extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/balancetalk/vote/domain/GameVote.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
import balancetalk.game.domain.GameOption;
import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import jakarta.persistence.*;
import lombok.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/balancetalk/vote/domain/TalkPickVote.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import balancetalk.talkpick.domain.TalkPick;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
Expand Down

0 comments on commit a56a4d2

Please sign in to comment.