1 | package com.example.rezevirajmasa.demo.model;
|
---|
2 |
|
---|
3 | import com.example.rezevirajmasa.demo.dto.PreorderedItemDto;
|
---|
4 | import com.fasterxml.jackson.annotation.JsonBackReference;
|
---|
5 | import com.fasterxml.jackson.annotation.JsonManagedReference;
|
---|
6 | import jakarta.persistence.*;
|
---|
7 | import lombok.Data;
|
---|
8 | import lombok.Getter;
|
---|
9 | import lombok.Setter;
|
---|
10 |
|
---|
11 | import java.math.BigDecimal;
|
---|
12 | import java.time.LocalDateTime;
|
---|
13 | import java.time.LocalTime;
|
---|
14 | import java.util.ArrayList;
|
---|
15 | import java.util.List;
|
---|
16 |
|
---|
17 | @Entity
|
---|
18 | @Table(name = "reservations")
|
---|
19 | @Data
|
---|
20 | public class Reservation {
|
---|
21 |
|
---|
22 | @Id
|
---|
23 | @GeneratedValue(strategy = GenerationType.IDENTITY)
|
---|
24 | @Column(name = "ReservationID")
|
---|
25 | private Long reservationID;
|
---|
26 |
|
---|
27 | @ManyToOne
|
---|
28 | @JoinColumn(name = "UserID")
|
---|
29 | @JsonBackReference(value = "user-reservations")
|
---|
30 | private User user;
|
---|
31 |
|
---|
32 | @ManyToOne
|
---|
33 | @JoinColumn(name = "TableNumber", nullable = false)
|
---|
34 | @JsonBackReference
|
---|
35 | private TableEntity table;
|
---|
36 |
|
---|
37 | @ManyToOne
|
---|
38 | @JoinColumn(name = "RestaurantID", nullable = false)
|
---|
39 | private Restaurant restaurant;
|
---|
40 |
|
---|
41 | @Column(name = "ReservationDateTime", nullable = false)
|
---|
42 | private LocalDateTime reservationDateTime;
|
---|
43 |
|
---|
44 | @Column(name = "PartySize")
|
---|
45 | private int partySize;
|
---|
46 |
|
---|
47 | @Column(name = "SpecialRequests")
|
---|
48 | private String specialRequests;
|
---|
49 |
|
---|
50 | @Column(name = "Status", length = 20, nullable = false)
|
---|
51 | private String reservationStatus;
|
---|
52 |
|
---|
53 | @Column(name = "CheckInTime")
|
---|
54 | private LocalDateTime checkInTime;
|
---|
55 |
|
---|
56 | @Getter
|
---|
57 | @Column(name = "CheckOutTime")
|
---|
58 | private LocalDateTime checkOutTime;
|
---|
59 |
|
---|
60 | @OneToMany(mappedBy = "reservation", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
---|
61 | private List<PreorderedItem> preOrderedItems = new ArrayList<>();
|
---|
62 |
|
---|
63 | @Column(name = "PaymentStatus", length = 20, nullable = false, columnDefinition = "VARCHAR default 'Unpaid'")
|
---|
64 | private String paymentStatus;
|
---|
65 |
|
---|
66 | public Reservation() {
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | @PrePersist
|
---|
71 | private void prePersist() {
|
---|
72 | if (reservationStatus == null) {
|
---|
73 | reservationStatus = "Pending";
|
---|
74 | }
|
---|
75 | if (paymentStatus == null) {
|
---|
76 | paymentStatus = "Unpaid";
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public Reservation(User user, TableEntity table, Restaurant restaurant, LocalDateTime reservationDateTime, int partySize, String specialRequests, String status, LocalDateTime checkInTime, LocalDateTime checkOutTime, String paymentStatus) {
|
---|
81 | this.table = table;
|
---|
82 | this.user = user;
|
---|
83 | this.restaurant = restaurant;
|
---|
84 | this.reservationDateTime = reservationDateTime;
|
---|
85 | this.partySize = partySize;
|
---|
86 | this.specialRequests = specialRequests;
|
---|
87 | this.reservationStatus = status;
|
---|
88 | this.checkInTime = checkInTime;
|
---|
89 | this.checkOutTime = checkOutTime;
|
---|
90 | this.paymentStatus = paymentStatus;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | @Override
|
---|
95 | public String toString() {
|
---|
96 | return "Reservation{" +
|
---|
97 | "reservationID=" + reservationID +
|
---|
98 | ", customer=" + user +
|
---|
99 | ", table=" + table +
|
---|
100 | ", restaurant=" + restaurant +
|
---|
101 | ", reservationDateTime=" + reservationDateTime +
|
---|
102 | ", partySize=" + partySize +
|
---|
103 | ", specialRequests='" + specialRequests + '\'' +
|
---|
104 | ", status='" + reservationStatus + '\'' +
|
---|
105 | ", checkInTime=" + checkInTime +
|
---|
106 | ", checkOutTime=" + checkOutTime +
|
---|
107 | ", paymentStatus='" + paymentStatus + '\'' +
|
---|
108 | '}';
|
---|
109 | }
|
---|
110 | } |
---|