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