Files
sumoc-backend/src/main/java/SuMoC/backend/notification/models/Notification.java
T
neuhauss fb41f80061
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
add NotificationLimiter to avoid sending too many notifications per hour
2026-02-05 11:56:24 +01:00

66 lines
1.7 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.Instant;
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
private String lastFailureReason;
@Column(nullable = false)
private Instant createdAt;
@Column(nullable = true)
private Instant sentAt = null;
public void incrementFailedSendAttempts() {
this.failedSendAttempts++;
}
}