From 860f8d27e439baf36d258a3804a1ead540f99c76 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Tue, 6 Feb 2024 18:34:19 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[ADD]=20=EC=BC=80=EC=9D=B4=ED=81=AC=20?= =?UTF-8?q?=EC=84=A0=EB=AC=BC=20=EC=9D=BC=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopterm/makeawish/domain/Present.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/domain/Present.java b/src/main/java/com/sopterm/makeawish/domain/Present.java index 7a5a79b..f0e12ca 100644 --- a/src/main/java/com/sopterm/makeawish/domain/Present.java +++ b/src/main/java/com/sopterm/makeawish/domain/Present.java @@ -6,18 +6,19 @@ import com.sopterm.makeawish.domain.wish.Wish; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +import java.time.LocalDateTime; @Getter @Entity @NoArgsConstructor +@EntityListeners(AuditingEntityListener.class) public class Present { @Id @GeneratedValue(strategy = IDENTITY) @@ -37,6 +38,9 @@ public class Present { @JoinColumn(name = "cake_id") private Cake cake; + @CreatedDate + protected LocalDateTime createdAt; + public static class PresentBuilder { private String name; private String message; From ebed03826cf4a2097be0b3dffc992c074939123b Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Tue, 6 Feb 2024 18:35:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20=EC=A4=84=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopterm/makeawish/domain/Present.java | 162 +++++++++--------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/domain/Present.java b/src/main/java/com/sopterm/makeawish/domain/Present.java index f0e12ca..d837830 100644 --- a/src/main/java/com/sopterm/makeawish/domain/Present.java +++ b/src/main/java/com/sopterm/makeawish/domain/Present.java @@ -1,99 +1,99 @@ package com.sopterm.makeawish.domain; -import static jakarta.persistence.FetchType.*; -import static jakarta.persistence.GenerationType.*; -import static java.util.Objects.*; - import com.sopterm.makeawish.domain.wish.Wish; - import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import java.time.LocalDateTime; +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static java.util.Objects.nonNull; + @Getter @Entity @NoArgsConstructor @EntityListeners(AuditingEntityListener.class) public class Present { - @Id @GeneratedValue(strategy = IDENTITY) - @Column(name = "present_id") - private Long id; - - private String name; - - @Column(columnDefinition = "TEXT") - private String message; - - @ManyToOne(fetch = LAZY) - @JoinColumn(name = "wish_id") - private Wish wish; - - @ManyToOne(fetch = LAZY) - @JoinColumn(name = "cake_id") - private Cake cake; - - @CreatedDate - protected LocalDateTime createdAt; - - public static class PresentBuilder { - private String name; - private String message; - private Wish wish; - private Cake cake; - - private PresentBuilder() {} - - public static PresentBuilder builder() { - return new PresentBuilder(); - } - - public PresentBuilder name(String name) { - this.name = name; - return this; - } - - public PresentBuilder message(String message) { - this.message = message; - return this; - } - - public PresentBuilder wish(Wish wish) { - this.wish = wish; - return this; - } - - public PresentBuilder cake(Cake cake) { - this.cake = cake; - return this; - } - - private void setWish(Present present, Wish wish) { - if (nonNull(present.wish)) { - present.wish.getPresents().remove(present); - } - present.wish = wish; - if (nonNull(wish)) { - wish.getPresents().add(present); - } - } - - public Present build() { - Present present = new Present(); - present.name = this.name; - present.message = this.message; - setWish(present, this.wish); - present.cake = this.cake; - return present; - } - } - - public static PresentBuilder builder() { - return new PresentBuilder(); - } + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "present_id") + private Long id; + + private String name; + + @Column(columnDefinition = "TEXT") + private String message; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "wish_id") + private Wish wish; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "cake_id") + private Cake cake; + + @CreatedDate + protected LocalDateTime createdAt; + + public static class PresentBuilder { + private String name; + private String message; + private Wish wish; + private Cake cake; + + private PresentBuilder() { + } + + public static PresentBuilder builder() { + return new PresentBuilder(); + } + + public PresentBuilder name(String name) { + this.name = name; + return this; + } + + public PresentBuilder message(String message) { + this.message = message; + return this; + } + + public PresentBuilder wish(Wish wish) { + this.wish = wish; + return this; + } + + public PresentBuilder cake(Cake cake) { + this.cake = cake; + return this; + } + + private void setWish(Present present, Wish wish) { + if (nonNull(present.wish)) { + present.wish.getPresents().remove(present); + } + present.wish = wish; + if (nonNull(wish)) { + wish.getPresents().add(present); + } + } + + public Present build() { + Present present = new Present(); + present.name = this.name; + present.message = this.message; + setWish(present, this.wish); + present.cake = this.cake; + return present; + } + } + + public static PresentBuilder builder() { + return new PresentBuilder(); + } }