From 649860efb6aaeb1efaf802198e41c9b7b748d72b Mon Sep 17 00:00:00 2001 From: matrixpower1004 Date: Fri, 29 Dec 2023 13:28:31 +0900 Subject: [PATCH] =?UTF-8?q?#13=20feat:=20=EC=98=88=EC=95=BD=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 수정된 ERD에 따라 예약 및 예약 객실 엔티티 수정 - Payment 엔티티 추가 --- .../upjuyanolja/domain/payment/Payment.java | 35 +++++++++++ .../reservation/entity/Reservation.java | 60 ++++++++++++------- .../reservation/entity/ReservationRoom.java | 35 ++--------- 3 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/payment/Payment.java diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/payment/Payment.java b/src/main/java/com/backoffice/upjuyanolja/domain/payment/Payment.java new file mode 100644 index 00000000..f3b23800 --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/payment/Payment.java @@ -0,0 +1,35 @@ +package com.backoffice.upjuyanolja.domain.payment; + +import com.backoffice.upjuyanolja.domain.reservation.entity.PayMethod; +import com.backoffice.upjuyanolja.global.common.BaseTime; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Comment; +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +public class Payment extends BaseTime { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Comment("결제 식별자") + private Long id; + + @Column(nullable = false, name = "pay_method") + @Enumerated(value = EnumType.STRING) + @Comment("결제 수단") + private PayMethod payMethod; + + + @Column(nullable = false, name = "final_price") + @Comment("최종 가격") + private int finalPrice; +} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/Reservation.java b/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/Reservation.java index facbc110..4acfac54 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/Reservation.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/Reservation.java @@ -2,19 +2,19 @@ import com.backoffice.upjuyanolja.domain.coupon.entity.Coupon; import com.backoffice.upjuyanolja.domain.member.entity.Member; +import com.backoffice.upjuyanolja.domain.payment.Payment; +import com.backoffice.upjuyanolja.domain.room.entity.Room; import com.backoffice.upjuyanolja.global.common.BaseTime; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; 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.OneToOne; +import java.time.LocalDate; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -30,39 +30,55 @@ public class Reservation extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Comment("예약 식별자") private Long id; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - @Comment("예약 숙소 식별자") - private ReservationRoom reservationRoom; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(nullable = false, name = "member_id") @Comment("회원 식별자") private Member member; + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "coupon_id") @Comment("쿠폰 식별자") private Coupon coupon; - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - @Comment("결제 수단") - private PayMethod payMethod; - @Column(nullable = false) - @Comment("결제 금액") - private int price; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "payment_id") + @Comment("결제 식별자") + private Payment payment; + + @Column(nullable = false, name = "visitor_name") + @Comment("방문자명") + private String visitorName; + + @Column(nullable = false, name = "visitor_phone") + @Comment("방문자 전화번호") + private String visitorPhone; + + @Column(nullable = false, name = "start_date") + @Comment("입실 일자") + private LocalDate startDate; + + @Column(nullable = false, name = "end_date") + @Comment("퇴실 일자") + private LocalDate endDate; @Builder - public Reservation( - Long id, - ReservationRoom reservationRoom, + public Reservation(Long id, Member member, Coupon coupon, - PayMethod payMethod, - int price - ) { + Payment payment, + String visitorName, + String visitorPhone, + LocalDate startDate, + LocalDate endDate) + { this.id = id; - this.reservationRoom = reservationRoom; this.member = member; this.coupon = coupon; - this.payMethod = payMethod; - this.price = price; + this.payment = payment; + this.visitorName = visitorName; + this.visitorPhone = visitorPhone; + this.startDate = startDate; + this.endDate = endDate; } } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/ReservationRoom.java b/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/ReservationRoom.java index 6b739b91..09146cce 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/ReservationRoom.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/reservation/entity/ReservationRoom.java @@ -10,7 +10,6 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import java.time.LocalDate; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -24,50 +23,28 @@ public class ReservationRoom extends BaseTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Comment("숙소 식별자") + @Comment("예약 객실 식별자") private Long id; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "reservation_id") @Comment("예약 식별자") private Reservation reservation; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "room_id") @Comment("객실 식별자") private Room room; + @Column(nullable = false) - @Comment("가격") + @Comment("객실가격") // 예약 결제 할 당시의 객실 가격 private int price; - @Column(nullable = false) - @Comment("숙박 시작일") - private LocalDate startDate; - @Column(nullable = false) - @Comment("숙박 마지막일") - private LocalDate endDate; - @Column(nullable = false) - @Comment("방문자명") - private String visitorName; - @Column(nullable = false) - @Comment("방문자 전화번호") - private String visitorPhone; @Builder - public ReservationRoom( - Long id, - Reservation reservation, - Room room, - int price, - LocalDate startDate, - LocalDate endDate, - String visitorName, - String visitorPhone - ) { + public ReservationRoom(Long id, Reservation reservation, Room room, int price) { this.id = id; this.reservation = reservation; this.room = room; this.price = price; - this.startDate = startDate; - this.endDate = endDate; - this.visitorName = visitorName; - this.visitorPhone = visitorPhone; } }