From e146a8ccedf30252f7b9a4c927cdd03318f82004 Mon Sep 17 00:00:00 2001 From: juha Date: Thu, 5 Sep 2024 17:55:48 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20not?= =?UTF-8?q?=20null,=20unique=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 3juhwan <13selfesteem91@naver.com> Co-authored-by: Arachneee Co-authored-by: kunsanglee --- .../haengdong/domain/action/BillAction.java | 10 +++++-- .../domain/action/BillActionDetail.java | 6 ++++ .../haengdong/domain/action/MemberAction.java | 11 ++++++-- .../domain/action/MemberGroupIdProvider.java | 11 -------- .../server/haengdong/domain/event/Event.java | 4 ++- .../haengdong/domain/event/EventStep.java | 28 ------------------- 6 files changed, 26 insertions(+), 44 deletions(-) delete mode 100644 server/src/main/java/server/haengdong/domain/action/MemberGroupIdProvider.java delete mode 100644 server/src/main/java/server/haengdong/domain/event/EventStep.java diff --git a/server/src/main/java/server/haengdong/domain/action/BillAction.java b/server/src/main/java/server/haengdong/domain/action/BillAction.java index d92d112d7..56ca8c20e 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillAction.java +++ b/server/src/main/java/server/haengdong/domain/action/BillAction.java @@ -9,8 +9,11 @@ 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.Table; +import jakarta.persistence.UniqueConstraint; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -25,6 +28,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"event_id", "sequence"})}) @Entity public class BillAction implements Comparable { @@ -38,16 +42,18 @@ public class BillAction implements Comparable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @JoinColumn(name = "event_id", nullable = false) @ManyToOne(fetch = FetchType.LAZY) private Event event; - @AttributeOverride(name = "value", column = @Column(name = "sequence")) + @AttributeOverride(name = "value", column = @Column(name = "sequence", nullable = false)) @Embedded private Sequence sequence; - @Column(length = MAX_TITLE_LENGTH) + @Column(nullable = false, length = MAX_TITLE_LENGTH) private String title; + @Column(nullable = false) private Long price; @OneToMany(mappedBy = "billAction", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) diff --git a/server/src/main/java/server/haengdong/domain/action/BillActionDetail.java b/server/src/main/java/server/haengdong/domain/action/BillActionDetail.java index ffdfe04a3..09776e0d3 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillActionDetail.java +++ b/server/src/main/java/server/haengdong/domain/action/BillActionDetail.java @@ -1,10 +1,12 @@ package server.haengdong.domain.action; +import jakarta.persistence.Column; 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.Getter; @@ -19,13 +21,17 @@ public class BillActionDetail { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @JoinColumn(nullable = false) @ManyToOne(fetch = FetchType.LAZY) private BillAction billAction; + @Column(nullable = false) private String memberName; + @Column(nullable = false) private Long price; + @Column(nullable = false) private boolean isFixed; public BillActionDetail(BillAction billAction, String memberName, Long price, boolean isFixed) { diff --git a/server/src/main/java/server/haengdong/domain/action/MemberAction.java b/server/src/main/java/server/haengdong/domain/action/MemberAction.java index 97824b1f7..18efc1611 100644 --- a/server/src/main/java/server/haengdong/domain/action/MemberAction.java +++ b/server/src/main/java/server/haengdong/domain/action/MemberAction.java @@ -10,7 +10,10 @@ 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.persistence.UniqueConstraint; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -20,25 +23,29 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"event_id", "sequence"})}) @Entity public class MemberAction implements Comparable { public static final int MIN_NAME_LENGTH = 1; - public static final int MAX_NAME_LENGTH = 4; + public static final int MAX_NAME_LENGTH = 8; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @JoinColumn(name = "event_id", nullable = false) @ManyToOne(fetch = FetchType.LAZY) private Event event; - @AttributeOverride(name = "value", column = @Column(name = "sequence")) + @AttributeOverride(name = "value", column = @Column(name = "sequence", nullable = false)) @Embedded private Sequence sequence; + @Column(nullable = false, length = MAX_NAME_LENGTH) private String memberName; + @Column(nullable = false) @Enumerated(EnumType.STRING) private MemberActionStatus status; diff --git a/server/src/main/java/server/haengdong/domain/action/MemberGroupIdProvider.java b/server/src/main/java/server/haengdong/domain/action/MemberGroupIdProvider.java deleted file mode 100644 index 9e32bd733..000000000 --- a/server/src/main/java/server/haengdong/domain/action/MemberGroupIdProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package server.haengdong.domain.action; - -import org.springframework.stereotype.Component; - -@Component -public class MemberGroupIdProvider { - - public Long createGroupId() { - return System.currentTimeMillis(); - } -} diff --git a/server/src/main/java/server/haengdong/domain/event/Event.java b/server/src/main/java/server/haengdong/domain/event/Event.java index bb5d53dbc..be8874414 100644 --- a/server/src/main/java/server/haengdong/domain/event/Event.java +++ b/server/src/main/java/server/haengdong/domain/event/Event.java @@ -26,12 +26,14 @@ public class Event { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(nullable = false, length = MAX_NAME_LENGTH) private String name; @Embedded - @AttributeOverride(name = "value", column = @Column(name = "password")) + @AttributeOverride(name = "value", column = @Column(name = "password", nullable = false)) private Password password; + @Column(nullable = false, unique = true) private String token; public Event(String name, String password, String token) { diff --git a/server/src/main/java/server/haengdong/domain/event/EventStep.java b/server/src/main/java/server/haengdong/domain/event/EventStep.java deleted file mode 100644 index 297abdb66..000000000 --- a/server/src/main/java/server/haengdong/domain/event/EventStep.java +++ /dev/null @@ -1,28 +0,0 @@ -package server.haengdong.domain.event; - -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Entity -public class EventStep { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - private Event event; - - private String name; - - private Long sequence; -}