Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix - 5 crash container when deploying to k8s - https://github.com/hamony/reservation-service/issues/5 #6

Merged
merged 8 commits into from
Mar 27, 2024
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.ubluetech.reservationservice.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.Getter;

@Embeddable
@Getter
class Guest {
@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ubluetech.reservationservice.domain;

import java.time.LocalDate;
import java.util.Set;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand All @@ -19,7 +20,12 @@ public class Reservation {
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Guest guest;
private Room room;

@OneToMany(mappedBy = "reservation",
cascade = CascadeType.ALL,
orphanRemoval = true)
private Set<Room> rooms;

private LocalDate checkInDate;
private LocalDate checkOutDate;
}
45 changes: 45 additions & 0 deletions src/main/java/com/ubluetech/reservationservice/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,58 @@
import java.math.BigDecimal;

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.Table;
import lombok.Getter;

@Entity
@Table(name = "reserved_room")
@Getter
class Room {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

// The parent reference is marked as non-updatable, to prevent breaking the equals/hashCode contract
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "reservation_id",
nullable = false,
updatable = false)
private Reservation reservation;

@Column(nullable = false)
private String roomNumber;

@Enumerated(EnumType.STRING)
private RoomType roomType;

@Column(nullable = false)
private BigDecimal price;

@Override
public int hashCode() {
return getClass().hashCode();
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;

if (!(obj instanceof Room))
return false;

return id != null &&
id.equals(((Room) obj).getId());
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ubluetech.reservationservice.domain;

public enum RoomType {
SINGLE, DOUBLE, STUDIO, QUEEN, KING, TWIN, LUXURY, SUITE, VILLA, SMOKING
}
Loading