-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from Make-A-Wish-Sopt/jiyoung_#172
[FIX] 선물 생성 시 날짜 저장 추가
- Loading branch information
Showing
1 changed file
with
87 additions
and
83 deletions.
There are no files selected for viewing
170 changes: 87 additions & 83 deletions
170
src/main/java/com/sopterm/makeawish/domain/Present.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +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.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 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; | ||
|
||
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(); | ||
} | ||
} |