source: src/main/java/com/example/rezevirajmasa/demo/model/Reservation.java@ 2518b3a

main
Last change on this file since 2518b3a was 2518b3a, checked in by Aleksandar Panovski <apano77@…>, 2 weeks ago

Added menu tag

succesfull testing and implemnation

  • Property mode set to 100644
File size: 3.5 KB
Line 
1package com.example.rezevirajmasa.demo.model;
2
3import com.fasterxml.jackson.annotation.JsonBackReference;
4import com.fasterxml.jackson.annotation.JsonManagedReference;
5import jakarta.persistence.*;
6import lombok.Data;
7import lombok.Getter;
8import lombok.Setter;
9
10import java.math.BigDecimal;
11import java.time.LocalDateTime;
12import java.time.LocalTime;
13import java.util.ArrayList;
14import java.util.List;
15
16@Entity
17@Table(name = "reservations")
18@Data
19public 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 @JsonBackReference(value = "user-reservations")
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 @OneToMany(mappedBy = "reservation", cascade = CascadeType.ALL, orphanRemoval = true)
64 private List<PreorderedItem> preOrderedItems = new ArrayList<>();
65
66 @Column(name = "PaymentStatus", length = 20, nullable = false, columnDefinition = "VARCHAR default 'Unpaid'")
67 private String paymentStatus;
68
69 public Reservation() {
70
71 }
72
73 @PrePersist
74 private void prePersist() {
75 if (status == null) {
76 status = "Pending";
77 }
78 if (paymentStatus == null) {
79 paymentStatus = "Unpaid";
80 }
81 }
82
83 public Reservation(User user, TableEntity table, Restaurant restaurant, LocalDateTime reservationDateTime, int partySize, String specialRequests, String status, LocalDateTime checkInTime, LocalDateTime checkOutTime, String paymentStatus) {
84 this.table = table;
85 this.user = user;
86 this.restaurant = restaurant;
87 this.reservationDateTime = reservationDateTime;
88 this.partySize = partySize;
89 this.specialRequests = specialRequests;
90 this.status = status;
91 this.checkInTime = checkInTime;
92 this.checkOutTime = checkOutTime;
93 this.paymentStatus = paymentStatus;
94 }
95
96
97 @Override
98 public String toString() {
99 return "Reservation{" +
100 "reservationID=" + reservationID +
101 ", customer=" + user +
102 ", table=" + table +
103 ", restaurant=" + restaurant +
104 ", reservationDateTime=" + reservationDateTime +
105 ", partySize=" + partySize +
106 ", specialRequests='" + specialRequests + '\'' +
107 ", status='" + status + '\'' +
108 ", checkInTime=" + checkInTime +
109 ", checkOutTime=" + checkOutTime +
110 ", paymentStatus='" + paymentStatus + '\'' +
111 '}';
112 }
113}
Note: See TracBrowser for help on using the repository browser.