61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
package SuMoC.backend.notification.models;
|
|
|
|
import SuMoC.backend.notification.enums.NotificationStatus;
|
|
import SuMoC.backend.notification.enums.NotificationType;
|
|
import SuMoC.backend.user.models.User;
|
|
import jakarta.persistence.*;
|
|
import lombok.*;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalTime;
|
|
|
|
@Entity
|
|
@Table(name = "notifications")
|
|
@Getter
|
|
@Setter
|
|
@Builder
|
|
@NoArgsConstructor
|
|
@AllArgsConstructor
|
|
public class Notification {
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@ManyToOne
|
|
@JoinColumn(name = "user_id", nullable = false)
|
|
private User user;
|
|
|
|
@Column(nullable = false)
|
|
@Enumerated(EnumType.STRING)
|
|
private NotificationType type;
|
|
|
|
@Column(columnDefinition = "TEXT")
|
|
private String data; // Store serialized DTO as JSON
|
|
|
|
/**
|
|
* Time of day from which on a notification might be sent.
|
|
* Useful since we might want to send messages about specific trips immediately but not inform about trend changes
|
|
* etc. in the middle of night when calculating jobs might run.
|
|
*/
|
|
@Column(nullable = false)
|
|
private LocalTime earliestTimeOfDayToSend;
|
|
|
|
@Column(nullable = false)
|
|
@Enumerated(EnumType.STRING)
|
|
private NotificationStatus status = NotificationStatus.PENDING;
|
|
|
|
/**
|
|
* Number of retry attempts made to send this notification.
|
|
*/
|
|
@Column(nullable = false)
|
|
private int failedSendAttempts = 0;
|
|
|
|
@Column(nullable = false)
|
|
|
|
private LocalDateTime createdAt;
|
|
|
|
public void incrementFailedSendAttempts() {
|
|
this.failedSendAttempts++;
|
|
}
|
|
}
|