diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/Alert.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/Alert.java index c69ce23e..8d65f95e 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/Alert.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/Alert.java @@ -1,9 +1,12 @@ package pl.ateam.disasteralerts.disasteralert; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; @@ -25,15 +28,12 @@ class Alert { @GeneratedValue private UUID id; - @Column(nullable = false) - private DisasterType type; + @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private Disaster disaster; @Column(nullable = false) - private String location; + private String description; @Column(nullable = false) private Instant creationDate; - - @Column(nullable = false) - private DisasterStatus status; } diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/Disaster.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/Disaster.java index 7f8ce3f5..5cec65c1 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/Disaster.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/Disaster.java @@ -4,6 +4,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; @@ -11,6 +12,7 @@ import lombok.Setter; import java.time.Instant; +import java.util.List; import java.util.UUID; @Entity @@ -41,4 +43,7 @@ class Disaster { @Column(nullable = false) private DisasterStatus status; + + @OneToMany + private List alerts; } diff --git a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterStatus.java b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterStatus.java index 57a6de50..c990bfb7 100644 --- a/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterStatus.java +++ b/src/main/java/pl/ateam/disasteralerts/disasteralert/DisasterStatus.java @@ -1,5 +1,5 @@ package pl.ateam.disasteralerts.disasteralert; enum DisasterStatus { - ACTIVE, FINISHED + ACTIVE, FINISHED, FAKE }