Notification.java
package com.rbctcsworld.ecommerce.notification;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
/** One e-mail in the outbox. */
@Entity
@Table(name = "notifications")
public class Notification {
public static final String PENDING = "PENDING";
public static final String SENDING = "SENDING";
public static final String SENT = "SENT";
public static final String FAILED = "FAILED";
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "order_id")
private Long orderId;
@Column(nullable = false)
private String recipient;
@Column(nullable = false, length = 30)
private String type;
@Column(nullable = false, length = 200)
private String subject;
@Column(nullable = false, length = 4000)
private String body;
@Column(nullable = false, length = 10)
private String status = PENDING;
@Column(nullable = false)
private int attempts;
@Column(name = "next_attempt_at", nullable = false)
private LocalDateTime nextAttemptAt;
@Column(name = "last_error", length = 300)
private String lastError;
@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;
@Column(name = "sent_at")
private LocalDateTime sentAt;
protected Notification() {
}
public Notification(Long orderId, String recipient, String type, String subject, String body, LocalDateTime now) {
this.orderId = orderId;
this.recipient = recipient;
this.type = type;
this.subject = subject;
this.body = body;
this.createdAt = now;
this.nextAttemptAt = now;
}
public Long getId() { return id; }
public Long getOrderId() { return orderId; }
public String getRecipient() { return recipient; }
public String getType() { return type; }
public String getSubject() { return subject; }
public String getBody() { return body; }
public String getStatus() { return status; }
public int getAttempts() { return attempts; }
public LocalDateTime getNextAttemptAt() { return nextAttemptAt; }
public String getLastError() { return lastError; }
public LocalDateTime getCreatedAt() { return createdAt; }
public LocalDateTime getSentAt() { return sentAt; }
}